第三方浏览器微信支付唤醒

wxpay_wap.php

 1 // 文档中说的,价格 单位是分
 2 $money = $_POST['money']*100; //商品价格
 3 // 前台请求的参数
 4 $title = $_POST['title']; //商品名称
 5 $userid = $_POST['userid']; //用户id
 6 
 7 $time = time();
 8 
 9 $nonce_str = "hcuasduvihasdiovjerjgvujsaru"; //随机字符串
10 $appid = "**********************"; //在微信开放平台中的 appid(先要创建一个移动应用)
11 $mch_id = "************";  //商户号,在商户平台中查看
12 $key = "*********************************"; //在微信开放平台中的 
13 $notify_url = "http://www.xxx.com/xxx/wxnotify.php"; //用户支付完后微信会来触发这个脚本,是处理业务逻辑的地方
14 //订单号可以灵活使用,比如我这个地方把userid加进去,在异步回调的时候方便直接操作用户
15 $out_trade_no = $time."__".$userid; 
16 
17 // 下面的参数含义直接看文档
18 $tmpArr = array(
19     'appid'=>$appid,   //不要填成了 公众号原始id
20     'attach'=>$title, 
21     'body'=>$title,
22     'mch_id'=>$mch_id,
23     'nonce_str'=>$nonce_str,  
24     'notify_url'=>$notify_url,
25     'out_trade_no'=>$out_trade_no, 
26     'spbill_create_ip'=>$_SERVER['REMOTE_ADDR'],
27     'total_fee'=>$money,
28     'trade_type'=>'MWEB' 
29     );
30 // 签名逻辑官网有说明,签名步骤就不解释了
31 ksort($tmpArr);  
32 
33 $buff = "";
34 foreach ($tmpArr as $k => $v)
35 {
36    $buff .= $k . "=" . $v . "&";
37 }
38 $buff = trim($buff, "&");
39 $stringSignTemp=$buff."&key=51b3363e91fe317fc346526f5933f15e";
40 $sign= strtoupper(md5($stringSignTemp)); //签名
41 
42 $xml = "<xml>
43            <appid>".$appid."</appid>
44            <attach>".$title."</attach>
45            <body>".$title."</body>
46            <mch_id>".$mch_id."</mch_id>
47            <nonce_str>".$nonce_str."</nonce_str>
48            <notify_url>".$notify_url."</notify_url>
49            <out_trade_no>".$out_trade_no."</out_trade_no>
50            <spbill_create_ip>".$_SERVER['REMOTE_ADDR']."</spbill_create_ip>
51            <total_fee>".$money."</total_fee>
52            <trade_type>MWEB</trade_type>
53            <sign>".$sign."</sign>
54         </xml> ";
55 
56 $posturl = "https://api.mch.weixin.qq.com/pay/unifiedorder";
57 
58 $ch = curl_init($posturl);
59 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
60 curl_setopt($ch, CURLOPT_POST, 1);  
61 curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); 
62 $response = curl_exec($ch);  
63 curl_close($ch);
64 
65 $xmlobj = json_decode(json_encode(simplexml_load_string($response, 'SimpleXMLElement', LIBXML_NOCDATA ))); 
66 exit($xmlobj->mweb_url);

 ------------------------------------------

wxpay_wap_notify.php

 1 // 本脚本的业务逻辑只是个例子,仅供参考
 2 
 3 // 拿到原始数据并通过xml类解析为对象
 4 $postObj = simplexml_load_string(file_get_contents("php://input"), 'SimpleXMLElement', LIBXML_NOCDATA );
 5 // 你可以通过下面这种方式来看一下微信究竟返回了那些参数,请保证log.php存在并且有写权限
 6 // file_put_contents(dirname(__file__)."/log.php",file_get_contents("php://input"));
 7 $arr = array();
 8 foreach ($postObj as $key => $value) {
 9     $arr[$key] = $value;
10 } 
11 // 订单状态
12 $status = $arr['result_code'];
13 
14 if(trim($status) == "SUCCESS") {
15     // 微信订单
16     $out_trade_no = $arr['transaction_id'];
17 
18         // 价格
19         $money = $arr['total_fee']/100;
20         // 在商户订单号中提取用户id,上一个脚本中我说了这个商户订单号可以灵活使用
21         $uid = explode("__", $arr['out_trade_no'])[1];
22 
23         // 在数据库中检查这个订单号是否已经处理过了 以免重复处理,因为很多原因微信可能多次触发本脚本
24         // checkrepeat(orderid);
25 
26         /
27                                                             /
28             这里处理业务逻辑....                            /    
29                                                             /            
30         /
31 
32         // 处理完逻辑 返回这个xml数据,告诉微信服务器,这个订单号已经处理完了 不要在来骚扰我了
33         $xml = "
34                 <xml>
35                   <return_code><![CDATA[".$status."]]></return_code>
36                   <return_msg><![CDATA[OK]]></return_msg>
37                 </xml>";
38         echo $xml;
39         
40 }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值