//提现
public function wx_withdrawal()
{
header('content-type:text/html;charset=utf-8');
$mch_appid = "xxxxx"; #appid
$key = "xxxxx"; #商户key
$mchid = "xxxx"; #商户号
$desc = '提现';
$openid = 'xxxxxx';
$check_name = 'NO_CHECK'; #此参数为不验证真实姓名,如果需要验证真实姓名,请参考微信文档,注意参数排序,否则将报错->签名错误
#$re_user_name=''; #微信真实姓名
$nonce_str = strtoupper(md5(time()));
$partner_trade_no = time() . rand(100, 999); #订单号
$amount = 0.3 * 100; #总金额 最小0.3,最大5000,以分为单位,金额*100
$spbill_create_ip = $_SERVER['REMOTE_ADDR'];
$www_url = $_SERVER['HTTP_HOST'];
$stringA = "amount={$amount}&check_name={$check_name}&desc={$desc}&mch_appid={$mch_appid}&mchid={$mchid}&nonce_str={$nonce_str}&openid={$openid}&partner_trade_no={$partner_trade_no}&spbill_create_ip={$spbill_create_ip}";
$stringSignTemp = $stringA . "&key=" . $key;
$sign = strtoupper(md5($stringSignTemp));
$postData =
"<xml>
<amount>{$amount}</amount>
<check_name>{$check_name}</check_name>
<desc>{$desc}</desc>
<mch_appid>{$mch_appid}</mch_appid>
<mchid>{$mchid}</mchid>
<nonce_str>{$nonce_str}</nonce_str>
<openid>{$openid}</openid>
<partner_trade_no>{$partner_trade_no}</partner_trade_no>
<spbill_create_ip>{$spbill_create_ip}</spbill_create_ip>
<sign>{$sign}</sign>
</xml>";
$url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers';
print_r($this->postCertXmlCurl($url, $postData)); #在这里post请求是要带证书,方法如下
die();
if ($dataxml['return_code'] == 'SUCCESS' && $dataxml['result_code'] == 'SUCCESS') {
#执行提现到账后的逻辑
echo '成功';
} else {
$this->error($dataxml['err_code_des']);
}
}
function postCertXmlCurl($url, $xml)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);//严格校验
//设置header
curl_setopt($ch, CURLOPT_HEADER, FALSE);
//要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);//证书检查
curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'pem');
curl_setopt($ch, CURLOPT_SSLCERT, $_SERVER['DOCUMENT_ROOT'] . '/cert/apiclient_cert.pem');
curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'pem');
curl_setopt($ch, CURLOPT_SSLKEY, $_SERVER['DOCUMENT_ROOT'] . '/cert/apiclient_key.pem');
// curl_setopt($ch,CURLOPT_SSLCERTTYPE,'pem');
// curl_setopt($ch,CURLOPT_CAINFO,dirname(__FILE__).'/cert/rootca.pem');
//post提交方式
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
//运行curl
$data = curl_exec($ch);
$objectxml = (array)simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA);
// $data = $this->xml_to_json($data);
return $objectxml;
// dump($objectxml);die;
}
特别注意一点 小程序需要开通提现相关接口 否则会提现失败
如果你的小程序用的是个人营业执照注册的 将不能申请提现业务
下面是接口错误:Array
(
[return_code] => SUCCESS
[return_msg] => NO_AUTH
[mch_appid] => xxxxxxxx
[mchid] => xxxxxxxxx
[result_code] => FAIL
[err_code] => NO_AUTH
[err_code_des] => 产品权限验证失败,请查看您当前是否具有该产品的权限
)
版权声明:本文为qq_56816632原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。