Thinkphp and onethink implement the payment plug-in, thinkphponethink. Thinkphp and onethink implement the payment plug-in, thinkphponethinkthinkPHP and micro-payment implement the payment plug-in, and call jssdk to implement the payment. here we have detailed code and Thinkphp and onethink implement the payment plug-in
ThinkPHP and micro-payment implementation of the payment plug-in, call jssdk to implement payment, here are detailed code and tutorials, see here:
// Implemented Wxpay hook method public function Wxpay ($ param) {require '. /Addons/Wxpay/WxPayPubHelper. php '; $ jsApi = new \ JsApi_pub (); // ========== Step 1: openid ============== if (! Isset ($ _ GET ['code']) {// return code $ url = $ jsApi-> createOauthUrlForCode (\ WxPayConf_pub: JS_API_CALL_URL. '/order_id /'. $ param ['Order _ id']); Header ("Location: $ url");} else {$ order_id = $ param ['Order _ id']; $ info = M ('order')-> where ('Id = '. $ order_id)-> find (); if (empty ($ info) | $ info ['is _ pay'] = 1) {dump ('This order does not exist or has been paid '. $ order_id); exit () ;}$ this-> assign ('info', $ info); $ a = $ info ['Money']; $ B = 100; $ c = $ a * $ B; // GET the code to GET openid $ code = $ _ GET ['code']; $ jsApi-> setCode ($ code ); $ openid = $ jsApi-> getOpenId ();} // ========== Step 2: use the unified payment interface, get prepay_id ================/// use the unified payment interface $ unifiedOrder = new \ UnifiedOrder_pub (); $ unifiedOrder-> setParameter ("openid ", "$ openid"); // product description $ unifiedOrder-> setParameter ("body", "online reservation"); // product description // custom order number, for example, $ timeStamp = time (); // $ out_trade_no = \ WxPayConf_pub: APPID. "$ timeStamp"; $ out_trade_no = $ info ['ordersn ']; $ unifiedOrder-> setParameter ("out_trade_no", "$ out_trade_no "); // merchant Order No. $ unifiedOrder-> setParameter ("total_eter", "$ c"); // Total Amount $ unifiedOrder-> setParameter ("policy_url", \ WxPayConf_pub: policy_url. '/order_id /'. $ param ['Order _ id']); // notification address $ unifiedOrder-> setParameter ("trade_type", "JSAPI "); // transaction type $ prepay_id = $ unifiedOrder-> getPrepayId (); // ========= Step 3: use jsapi to initiate a payment =============$ jsApi-> setPrepayId ($ prepay_id); $ jsApiParameters = $ jsApi-> getParameters (); $ this-> assign ('jsapiparameters ', $ jsApiParameters); $ this-> display ('pae ');}
The above is all the content of this article. I hope it will help you learn PHP programming.
Articles you may be interested in:
- What is OneThink oneThink to add a plug-in the background?
ThinkPHP and micro-payment implementation of the payment plug-in, call jssdk to implement payment, here there are detailed code and...