Thinkphp and onethink implement the payment plug-in, thinkphponethink
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?