In this WeChat public platform development tutorial, we will introduce how to develop and implement the network-wide publishing function of WeChat payment.
Network-wide release refers to the detection and release of the rights protection function, alarm interface, and delivery interface in the last step of the WeChat payment background.
This article is divided into the following three parts:
WeChat payment directory setting
Delivery interface adjustment
Adjustment of rights protection interface and alarm interface
1. WeChat payment directory setting
The setting of WeChat payment URL is closely related to the adjustment of WeChat payment. The several URL settings we use here are as follows:
Payment test URL: http://www.fangbei.org/wxpay/jsapi/index.php
Transaction notification URL: http://www.fangbei.org /wxpay/notify/index.php
Rights notification URL: http://www.fangbei.org/wxpay/rights/index.php
Alarm notification URL: http://www.fangbei.org/wxpay /alarm/index.php
2. Adjustment of the shipping interface
Before adjusting the shipping interface, the user needs to have a transaction before sending, so first Complete a jsapi payment, the code is as follows,
<?php include_once("WxPayHelper.php"); $commonUtil = new CommonUtil(); $wxPayHelper = new WxPayHelper(); $wxPayHelper->setParameter("bank_type", "WX"); $wxPayHelper->setParameter("body", "方倍微信支付测试"); $wxPayHelper->setParameter("partner", PARTNERID); $wxPayHelper->setParameter("out_trade_no", $commonUtil->create_noncestr()); $wxPayHelper->setParameter("total_fee", "1"); $wxPayHelper->setParameter("fee_type", "1"); $wxPayHelper->setParameter("notify_url", "http://www.fangbei.org/wxpay/notify/index.php"); $wxPayHelper->setParameter("spbill_create_ip", $_SERVER['REMOTE_ADDR']); $wxPayHelper->setParameter("input_charset", "GBK"); $biz_package=$wxPayHelper->create_biz_package(); ?> <html> <meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;"> <script language="javascript"> function callpay() { WeixinJSBridge.invoke('getBrandWCPayRequest',<?php echo $biz_package;?>,function(res){ WeixinJSBridge.log(res.err_msg); alert(res.err_code+res.err_desc+res.err_msg); }); } </script> <body> <button type="button" onclick="callpay()">方倍微信支付测试</button> </body> </html>
When the above transaction is completed, the transaction notification interface will call back the URL with parameters, as follows
http://www.fangbei.org/wxpay/notify/index.php?discount=0&fee_type=1&input_charset=GBK¬ify_id=aCi-cg4m1nr2bbg-De-MK6hQum8XVsw4mYfYnD5umAiEm_J6P_MalPvOisl2NJdurzTW-TJ9IPcnKmZm5TpKjrc8bXT6PEe0&out_trade_no=5DlIL2s5DGR8147c&partner=1219951701&product_fee=1&sign=A7AEF7AE3B70C54C3C0FF642DD2E2004&sign_type=MD5&time_end=20140808185647&total_fee=1&trade_mode=1&trade_state=0&transaction_id=1219951701201408083366666764&transport_fee=0
At the same time, POST sent the following XML data
<xml> <OpenId><![CDATA[ocIywt7h42MwHxXx23sJdBpBV7Q8]]></OpenId> <AppId><![CDATA[wxa8826d0c0c0b6d6a]]></AppId> <IsSubscribe>1</IsSubscribe> <TimeStamp>1407495408</TimeStamp> <NonceStr><![CDATA[D6iywdqlcdUj8nDQ]]></NonceStr> <AppSignature><![CDATA[a99a3cb4f5377dc30cca3f7b362412d7e468e0f4]]></AppSignature> <SignMethod><![CDATA[sha1]]></SignMethod> </xml>
Take out the
transaction_id=1219951701201408083366666764 out_trade_no=5DlIL2s5DGR8147c
in the url and the
<OpenId><![CDATA[ocIywt7h42MwHxXx23sJdBpBV7Q8]]></OpenId>
in the xml and fill the above 3 parameter values into the delivery interface. For the code, please refer to WeChat Payment Development Delivery Notice
Run it once and the delivery notification interface will be opened.
3. Adjustment of the rights protection interface and the alarm interface
The adjustment of the rights protection interface and the alarm interface is very simple, because the official only needs to receive a response. Therefore, success is returned directly in the corresponding index.php. The code is as follows:
<?php echo "success"; ?>
4. Effect diagram
After the above three interfaces are adjusted, it can be released to the entire network. The effect is as follows
#For more articles related to WeChat payment development published across the entire network, please pay attention to the PHP Chinese website!