文件
註:開放平台的微信支付和公眾號的微信支付是不一樣的,公眾平台和開放平台的支付申請下來之後會有各自對應的商家平台帳號
<code>function wechat($appid,$mchid,$appkey,$cert_path,$key_path,$order_id,$openid,$amount,$desc){ $arr = [ 'mch_appid'=>$appid,//注意区分公众号和app商户号不同 'mchid'=>$mchid, 'nonce_str'=>str_random(32),//随机数 'partner_trade_no'=>$order_id,//自己定义一个不重复订单号 'openid'=>$openid,//微信openid 通过微信授权登录获取 'check_name'=>'NO_CHECK', 'amount'=>$amount*100,//注意这里传给微信的单位是分 'desc'=>$desc, 'spbill_create_ip'=>\Request::getClientIp(), 'sign'=>'', ]; ksort($arr); $sign=""; foreach ($arr as $key => $value) { if($value && $key!="sign" && $key!="key"){ $sign.=$key."=".$value."&"; } } $sign.="key=".$appkey;//商户后台自定义的 $arr['sign'] = strtoupper(md5($sign)); $xml = "<xml>"; foreach ($arr as $key=>$val) { if (is_numeric($val)) { $xml.="<".$key.">".$val."</".$key.">"; } else $xml.="<".$key."><![CDATA[".$val."]]></".$key.">"; } $xml.="</xml>"; $ch = curl_init(); //超时时间 curl_setopt($ch,CURLOPT_TIMEOUT,60); curl_setopt($ch,CURLOPT_URL,'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers'); curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false); curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false); //默认格式为PEM curl_setopt($ch,CURLOPT_SSLCERTTYPE,'PEM'); curl_setopt($ch,CURLOPT_SSLCERT,$cert_path);//注意区分公众号和app商户号的证书不同,需要到pay.weixin.qq.com后台下载 curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM'); curl_setopt($ch,CURLOPT_SSLKEY,$key_path); curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml')); curl_setopt($ch,CURLOPT_POST, 1); curl_setopt($ch,CURLOPT_POSTFIELDS,$xml); $data = curl_exec($ch); $data = json_decode(json_encode(simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA)), true); curl_close($ch); return $data;//$data['return_code'] == 'SUCCESS' && $data['result_code'] == 'SUCCESS' 支付成功 } }</code>
附:
https://youqingkui .me/note/e57abb2a-3997-47f1-b9fe-ac94740130ce
python版微信支付
http://bblove.me/2015/10/25/weixin-app-pay-v3-0/
微信件php sdk開發教學
https://github.com/fanhefan/wechat_app_pay
微信紅包API介面
http://jeffchen.sinaapp.com/
http://tao.logdown.com/posts/195357-micro -payments-app-integration
以上就介紹了 微信app支付,包括了github方面的內容,希望對PHP教程有興趣的朋友有所幫助。