Thinkphp and onethink implement WeChat payment plug-in

Source: Internet
Author: User
Tags learn php programming openid
This article mainly introduces Thinkphp and onethink implementation payment plug-ins in detail. if you are interested, you can refer to thinkPHP and the micro-payment implementation payment plug-ins and call jssdk to implement payment, here are detailed code and tutorials. for details, refer to the following:

// 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.