当前位置:网站首页>TP5 wechat withdrawal merchants transfer to change (copying is available)
TP5 wechat withdrawal merchants transfer to change (copying is available)
2022-07-19 08:47:00 【success_ a】
At the beginning, the docking enterprise pays change , After docking, we found a prompt that the product permission is not opened .
After consulting the information, it was found that the original enterprise payment to change was changed to merchant withdrawal to change , Therefore, the following code is provided .
Applicable to : Direct connection merchants
request URL:https://api.mch.weixin.qq.com/v3/transfer/batches
Request mode :POST
Interface frequency limiting : Single merchant 50QPS, If the frequency limit is exceeded , Will report a mistake FREQUENCY_LIMITED, Please reduce the frequency of requests .
Do you need a certificate : yes
public function myTixian()
{
$this->tixian($info);
}
// Withdrawal
public function tixian($info = [])
{
if (empty($info)){
return false;
}
$url = 'https://api.mch.weixin.qq.com/v3/transfer/batches';
$batch_name = ' User withdrawal ';
$pars = [];
$pars['appid'] = 'wx1xxxxx';// Directly connected merchants appid
$pars['out_batch_no'] = 'sjzz'.date('Ymd').mt_rand(1000, 9999);// Merchant batch number in merchant system , It is required that this parameter can only be represented by numbers 、 Upper and lower case letters make up , Unique within the merchant system
$pars['batch_name'] = $batch_name;// Name of the batch transfer
$pars['batch_remark'] = $batch_name;// Transfer instructions ,UTF8 code , Most allow 32 Characters
$pars['total_amount'] = intval(strval($info['amount'] * 100));// Total transfer amount Unit is “ branch ”
$pars['total_num'] = 1;// Total number of transfers
$pars['transfer_detail_list'][0] = [
'out_detail_no'=> $info['orderno'],
'transfer_amount'=>intval(strval($info['amount'] * 100)),
'transfer_remark'=>$batch_name,
'openid'=>$info['openid'],
];// Transfer details list
$token = $this->getToken($pars);// obtain token
$res = $this->https_request($url,json_encode($pars),$token);// Send a request
$resArr = json_decode($res,true);
dump($resArr);die();
}
public function getToken($pars)
{
$url = 'https://api.mch.weixin.qq.com/v3/transfer/batches';
$http_method = 'POST';// Request method (GET,POST,PUT)
$timestamp = time();// Request timestamp
$url_parts = parse_url($url);// Gets the absolute value of the request URL
$nonce = $timestamp.rand('10000','99999');// Request random string
$body = json_encode((object)$pars);// Request message body
$stream_opts = [
"ssl" => [
"verify_peer"=>false,
"verify_peer_name"=>false,
]
];
// certificate
$apiclient_cert_path = '/www/wwwroot/xxxx/xxxx/key/apiclient_cert.pem';
$apiclient_key_path = '/www/wwwroot/xxxx/xxxx/key/apiclient_key.pem';
$apiclient_cert_arr = openssl_x509_parse(file_get_contents($apiclient_cert_path,false, stream_context_create($stream_opts)));
$serial_no = $apiclient_cert_arr['serialNumberHex'];// Certificate serial number
$mch_private_key = file_get_contents($apiclient_key_path,false, stream_context_create($stream_opts));// secret key
$merchant_id = 'xxxxx';// Merchant id
$canonical_url = ($url_parts['path'] . (!empty($url_parts['query']) ? "?${url_parts['query']}" : ""));
$message = $http_method."\n".
$canonical_url."\n".
$timestamp."\n".
$nonce."\n".
$body."\n";
openssl_sign($message, $raw_sign, $mch_private_key, 'sha256WithRSAEncryption');
$sign = base64_encode($raw_sign);// Signature
$schema = 'WECHATPAY2-SHA256-RSA2048';
$token = sprintf('mchid="%s",nonce_str="%s",timestamp="%d",serial_no="%s",signature="%s"',
$merchant_id, $nonce, $timestamp, $serial_no, $sign);// Wechat returns token
return $token;
}
function https_request($url,$data = null,$token){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, (string)$url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($data)){
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// Add request header
$headers = [
'Authorization:WECHATPAY2-SHA256-RSA2048 '.$token,
'Accept: application/json',
'Content-Type: application/json; charset=utf-8',
'User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
];
if(!empty($headers)){
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
}
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
边栏推荐
- Li Kou 1669 merges two linked list notes
- rosbridge
- 2022 Guangdong Provincial Safety Officer a certificate, the third batch (main person in charge) exercise questions and mock examination
- LeetCode 剑指 Offer II 041. 滑动窗口的平均值:低空间消耗解决
- oop_ Reference type variable transfer value
- MySQL中查询一个字符串字段的值不为空到底该怎么写?
- Junit5
- idea按条件断点调试
- mysql 初始化修改密码问题
- Example description of alternative writing of instanceof
猜你喜欢

gradle入门笔记

Baidu Apollo

项目代码训练教程

【人脸识别】基于直方图Histogram实现人脸识别附matlab代码
![Paddleserving service deployment tensorrt reports an error, shape of TRT subgraph is [-1, -1768],](/img/15/5dde91261a44fcfeda4d8436bb8559.png)
Paddleserving service deployment tensorrt reports an error, shape of TRT subgraph is [-1, -1768],

LeetCode 0116. Populate the next right node pointer for each node

cut,sort,uniq,xargs

【回归预测】基于粒子滤波实现锂离子电池寿命预测附matlab代码

idea按条件断点调试

Change the theme of hbuilderx into vscode
随机推荐
Bean的作用域和生命周期
分布式事务-可靠消息最终一致性解决方案
6-9漏洞利用-Telnet登陆提权
Project code training tutorial
Stm32subeide (9) -- USART sends and receives via DMA
Hausdorff loss function for semantic segmentation
JS learning notes 14-15: JS array and array letter quantity
Softmax 回归 + 损失函数 + 图片分类数据集
Matlab imports floating-point numbers with more than 9 digits after the decimal point
Solutions to license invalidation caused by MATLAB update
一文,教你实现单点登录
石墨厚度测量
Leetcode sword finger offer II 041 Average value of sliding window: low space consumption solution
软件测试需要学习多久?
Sorting out of neural network basics exercises in the second week of in-depth study
深度学习之线性回归+基础优化
cut,sort,uniq,xargs
Ribbon load balancing service call
Li Kou 43 string multiplication note
AuthTalk 第一期预告 | 全面拆解多租户解决方案