Thinkphp and Onethink implement WeChat payment plugin thinkphp3.1 laravel thinkphp if

Source: Internet
Author: User
thinkphp and micro-payment implementation of the payment plug-in, called in the JSSDK implementation payment, here are detailed code and tutorials, specifically see here:

The implementation of the Wxpay hook method public Function Wxpay ($param) {require './addons/wxpay/wxpaypubhelper/wxpaypubhelper.php ';              $jsApi = new \jsapi_pub (); ========= Step 1: Web authorization to get user openid============ if (!isset ($_get[' code ')) {//Trigger return code code $URL = $jsApi-& Gt;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 (' The 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 unified payment interface, get prepay_id============//Use unified Payment Interface $unifiedOrder = new \uniFiedorder_pub (); $unifiedOrder->setparameter ("OpenID", "$openid");//Description $unifiedOrder->setparameter ("Body", "online booking")//Product Description/ /custom order number, for example only $timeStamp = time (),//$out _trade_no = \wxpayconf_pub::appid. "      $timeStamp ";      $out _trade_no = $info [' ORDERSN ']; $unifiedOrder->setparameter ("Out_trade_no", "$out _trade_no");//Merchant Order number $unifiedOrder->setparameter ("Total_ Fee "," $c ");//Total Amount $unifiedOrder->setparameter (" Notify_url ", \wxpayconf_pub::notify_url. ' /order_id/'. $param [' order_id ']);//Notification address $unifiedOrder->setparameter ("Trade_type", "JSAPI");//transaction type $prepa      y_id = $unifiedOrder->getprepayid ();      ========= Step 3: Use JsApi to adjust the payment ============ $jsApi->setprepayid ($prepay _id);      $jsApiParameters = $jsApi->getparameters ();       $this->assign (' jsapiparameters ', $jsApiParameters);    $this->display (' pay '); }

The above is the whole content of this article, I hope that you learn PHP programming help.

The above describes the thinkphp and Onethink implementation of payment plug-ins, including the thinkphp aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

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