Thinkphp and Onethink implement micro-letter payment plug-in _php skills

Source: Internet
Author: User
Tags learn php openid

Thinkphp and micro-payment implementation of the micro-payment plug-in, in the micro-letter call micro-letter JSSDK Implementation Payment, here are detailed code and tutorials, specifically look here:

Implemented Wxpay Hook method public Function Wxpay ($param) {require './addons/wxpay/wxpaypubhelper/wxpaypubhelper.php '; 
       
      $jsApi = new \jsapi_pub (); ========= Step 1: Web page authorization to obtain user openid============ if (!isset ($_get[' code ')) {//Trigger micro-letter return code $url = $j Sapi->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 code to get the OpenID $code = $_get[' code '];
        $jsApi->setcode ($code);
      $openid = $jsApi->getopenid (); //========= Step 2: Use the unified payment interface to obtain prepay_id============//Use UnifiedPayment interface $unifiedOrder = new \unifiedorder_pub ();
      $unifiedOrder->setparameter ("OpenID", "$openid");//Product Description $unifiedOrder->setparameter ("Body", "online booking");//Product Description
Custom order number, here 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 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 $PR
      epay_id = $unifiedOrder->getprepayid ();
      ========= Step 3: Use Jsapi to adjust payment ============ $jsApi->setprepayid ($prepay _id);
      $jsApiParameters = $jsApi->getparameters ();
 
      $this->assign (' jsapiparameters ', $jsApiParameters);
    $this->display (' pay '); }

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

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.