php微信支付商户免充值代金券接口升级
//todo 如果没安装该插件可删除该行,并使用参数requestType改为‘1’
use GuzzleHttp\Client;/*** Class Demo* @package ShopEM\Services\WechatPay* 微信支付商户免充值代金券接口升级验收*/
class RechargeFreeVoucherDemo
{/*** @var int 请求方式* 1 使用curl* 2 使用插件 GuzzleHttp\Client*/protected $requestType = 1;/*** @var string 32随机数*/protected $nonceStr = '5K8264ILTKCH16CQ2502SI8ZNMTM67VS';/*** @var string 微信支付密钥*/protected $signKey = '你的微信支付密钥'; //todo/*** @var string 商户号*/protected $mchId = '你的商户号'; //todo/*** @var string 通过sign方法获取沙箱验签秘钥*/protected $sandBoxKey = '沙箱验签秘钥'; //todo/*** @var bool 返回数据是否xml转化array*/protected $openXmlArr = true;/*** DateTime : 2021/8/24 19:19* @Author : sun* 字段拼接*/public static function getSignContent($data): string{$buff = '';foreach ($data as $k => $v) {$buff .= ('sign' != $k && '' != $v && !is_array($v)) ? $k . '=' . $v . '&' : '';}return trim($buff, '&');}/*** 作用:array转xml*/function arrayToXml($arr){$xml = "<xml>";foreach ($arr as $key => $val) {if (is_numeric($val)) {$xml .= "<" . $key . ">" . $val . "</" . $key . ">";} else$xml .= "<" . $key . "><![CDATA[" . $val . "]]></" . $key . ">";}$xml .= "</xml>";return $xml;}/*** 作用:将xml转为array*/public function xmlToArray($xml){//将XML转为array$array_data = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);return $array_data;}#签名public function getsignkey($data, $box = true){$key = $this->sandBoxKey;#填写你的秘钥 ,后面几步用沙盒密钥if (!$box) $key = $this->signKey;ksort($data);$string = md5(self::getSignContent($data) . '&key=' . $key);return strtoupper($string);}#第一步 获取沙箱验签秘钥public function sign(){$data = ['mch_id' => $this->mchId,'nonce_str' => $this->nonceStr];$data['sign'] = $this->getsignkey($data, false);$url = 'https://api.mch.weixin.qq.com/sandboxnew/pay/getsignkey';$result = $this->post($data, $url);if ($this->openXmlArr) if ($this->openXmlArr) $result = $this->xmlToArray($result);return $result;}#第二步 「1003-可选用例-公众号/APP/扫码正常支付」验收#1.统一下单public function pay(){//total_fee 必须为551$data = ['appid' => 'wxd678efh567hg6787','body' => '测试商品','mch_id' => $this->mchId,'nonce_str' => $this->nonceStr,'notify_url' => 'http://www.weixin.qq.com/wxpay/pay.php','out_trade_no' => '201208241848','spbill_create_ip' => '192.168.10.10','total_fee' => '552','trade_type' => 'JSAPI'];$url = 'https://api.mch.weixin.qq.com/sandboxnew/pay/unifiedorder';$data['sign'] = $this->getsignkey($data);$result = $this->post($data, $url);if ($this->openXmlArr) $result = $this->xmlToArray($result);return $result;}#2.查询订单public function query(){$data = ['appid' => 'wxd678efh567hg6787','mch_id' => $this->mchId,'nonce_str' => $this->nonceStr,'out_trade_no' => '201208241848',];$url = 'https://api.mch.weixin.qq.com/sandboxnew/pay/orderquery';$data['sign'] = $this->getsignkey($data);$result = $this->post($data, $url);if ($this->openXmlArr) $result = $this->xmlToArray($result);return $result;}#第三步 「1003-可选用例-公众号/APP/扫码支付退款」验收#1.申请退款public function refund(){//refund_fee 必须为552$data = ['appid' => 'wxd678efh567hg6787','mch_id' => $this->mchId,'nonce_str' => $this->nonceStr,'out_trade_no' => '201208241848','out_refund_no' => 'TM201208241848','refund_fee' => '552','total_fee' => '552',];$data['sign'] = $this->getsignkey($data);$url = 'https://api.mch.weixin.qq.com/sandboxnew/pay/refund';$result = $this->post($data, $url);if ($this->openXmlArr) $result = $this->xmlToArray($result);return $result;}#2.查询退款public function refundquery(){$data = ['appid' => 'wxd678efh567hg6787','mch_id' => $this->mchId,'nonce_str' => $this->nonceStr,'out_trade_no' => '201208241848',];$data['sign'] = $this->getsignkey($data);$url = 'https://api.mch.weixin.qq.com/sandboxnew/pay/refundquery';$result = $this->post($data, $url);if ($this->openXmlArr) $result = $this->xmlToArray($result);return $result;}#第四步 「1005-必选用例-交易对账单下载」 验收public function downloadbill(){$data = ['appid' => 'wxd678efh567hg6787','bill_date' => '20120824','bill_type' => 'ALL','mch_id' => $this->mchId,'nonce_str' => $this->nonceStr,'out_trade_no' => '201208241848',];$data['sign'] = $this->getsignkey($data);$url = 'https://api.mch.weixin.qq.com/sandboxnew/pay/downloadbill';$result = $this->post($data, $url);return $result;}/*** DateTime : 2021/8/24 19:06* @Author : sun* @param $data* @param $url* post 请求*/public function post($data, $url){#两种请求方式if ($this->requestType === 1) {return $this->curlPost($data, $url);}if ($this->requestType === 2) {return $this->postXmlCurl($data, $url);}print_r('请求参数错误');exit;}/*** 作用:以post方式提交xml到对应的接口url*/public function postXmlCurl($data, $url){$xml = $this->arrayToXml($data);$httpClient = new Client();$response = $httpClient->request('POST', $url, ['body' => $xml]);$return = $response->getBody()->getContents();return $return;}/*** DateTime : 2021/8/24 19:03* @Author : sun* curl 请求方式*/public function curlPost($data, $url){$xmlData = $this->arrayToXml($data);$header[] = "Content-type: text/xml"; //定义content-type为xml,注意是数组$ch = curl_init($url);curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_HTTPHEADER, $header);curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlData);$response = curl_exec($ch);if (curl_errno($ch)) {print curl_error($ch);}curl_close($ch);return $response;}
}
php微信支付商户免充值代金券接口升级相关推荐
- 微信服务商开通免充值代金券接口升级验收
微信服务号开通免充值代金券接口升级验收 一.获取沙箱验签秘钥API 准备参数: 1.服务商商户号:mch_id 2.32位随机字符串:nonce_str 3.微信支付商户32位秘钥:key(获取签名s ...
- 微信支付免充值代金券接口升级免费开通步骤
无论是微信支付服务商还是普通商户,在创建代金券或立减折扣时,都希望能够实现免充值,在交易发生时直接抵扣,毕竟充值过程太啰嗦. 但是在微信支付商户平台上开通免充值相关产品(包括微信支付免充值代金券和微信 ...
- 微信支付--代金券免充值代金券:接口升级
微信支付–代金券免充值代金券 开通免充值代金券需 进行接口升级: https://pay.weixin.qq.com/wiki/doc/api/download/mczyscsyl.pdf 接口升级组 ...
- 微信免充值代金券与免充值立减券与单品券活动验收流程
功能介绍 为支持商户免充值营销经费开展运营活动,提升运营效率,微信支付特开发免充值营销产品功能.商户开通该产品功能后,可免费使用微信支付提供的免充值代金券.立减.折扣等营销工具.商户配置使用免充值代金 ...
- 微信支付(商户平台)卡券开发文档
文章目录 简介 代金券 代金券分类 预充值代金券 免充值代金券 发券渠道 二维码发券 营销活动发券 高级API接口发券 核销方式 支付中自动核销券 操作指引 开发前准备 开通代金券权限 下载API证书 ...
- 微信免资金代金券(V3版)java代码
开始之前先让博主吐槽下微信的接口文档与接口规则.一个代金券的模块搞了3个星期.严重怀疑微信的产品经理跟项目经理有病.写文档的程序员也是.吐槽结束. 一.准备 微信公众号的AppId和密钥Secret ...
- 微信支付分免密支付接口服务如何开通?
1.支付分免密扣款的实现流程: 用户使用完服务,商户调用支付分完结接口发起扣款,微信支付将代商户进行免密代扣. 若扣款失败,商户无需再次发起扣款申请,微信支付将按一定频次,再次发起免密代扣,直到扣款成 ...
- WxJava springboot微信支付商户直连分账使用总结
最近在做共享洗车小程序中有些店铺是采用按用户充值比例分账的模式和店主合作,故此记录下分账模式的使用. 建议先在官网看一遍大概流程 微信支付-分账-官网链接 准备工作 登录微信支付商户,设置好V3密匙 ...
- php 微信提现,微信支付商户提现功能介绍
微信支付商户提现功能介绍 微信支付商户提现功能介绍 1)提现产品简介 提现作为资金流转基础功能,为商户提供将资金从商户平台提现至商户号关联银行卡的能力,分为自动提现和手动提现.自动提现为系统自动执行, ...
最新文章
- ROOT android 原理。 基于(zergRush)
- R语言grep函数和grepl函数字符匹配实战
- 我三年开发经验,从字节跳动抖音离职后,原理+实战+视频+源码
- javascript技巧及常用事件方法集合(全)
- 如何处理Maven build错误 Non-Resolvable parent POM
- node.js npm常用命令
- leetcode542. 01 矩阵(bfs/dp)
- 微服务+异步工作流+ Serverless,Netflix 决定弃用稳定运行 7 年的旧平台
- qtabwidget放大_Qt自定义弹窗屏蔽父窗口(QWidget设置setWindowModality(Qt::ApplicationModal);以后再show)...
- 4. Spring Boot 过滤器、监听器
- 批处理打开和关闭oracle11g 服务
- android-手势-基础知识总结
- 剑指offer——python【第16题】合并两个有序链表
- cv2.error: OpenCV(4.5.3) :-1: error: (-5:Bad argument) in function ‘line‘ 报错解决
- python ConfigParser模块 配置文件解析
- matlab2016a最新安装教程
- 经典商业模式案例第1例:校园O2O
- 淘宝前员工开发雨滴阅读,欲打造国产Instapaper
- Windows下usb接口驱动技术(一)
- 华为MateBook E 12.6英寸 win11 16g+512g 轻评测