Home >php教程 >php手册 >thinkphp3.2.3 WeChat payment_scan code payment_with callback

thinkphp3.2.3 WeChat payment_scan code payment_with callback

WBOY
WBOYOriginal
2016-09-23 03:29:583044browse

Modify the WeChat payment example code into the example code used directly in tp, and simply make scan code payment and callback functions
Modify the WeChat payment sample code into the sample code used directly in tp, and simply make scan code payment and callback functions
Mode 2 is used. If necessary, you can directly execute the code in mode 1.
Class import Take a look at my import and you will understand how to import it. You don’t have to worry about this stuff anymore.
The code reference is as follows
Example code for generating payment QR code: public function index() {<br> Import ( "@.Controller.WxPay.WxPayNativePay" );<br>         $notify = new WxPayNativePay ();<br>         $url1 = $notify->GetPrePayUrl ( "123456789" );<br> ​​​​//Mode 2<br>            /**<br>            * Process: <br> * 1. Call unified ordering, get code_url, and generate QR code<br> ​​​​​* 2. Users scan the QR code to make payment<br> * 3. After the payment is completed, the WeChat server will notify you that the payment was successful<br> * 4. In the payment success notification, you need to check the order to confirm whether the payment is actually successful (see: notify.php) <br>                                                                                                                                                                */<br>              // $price = $_POST ['price'];<br>               // $prodect_id = $_POST ['prodect_id'];<br>             // $premission_name = $_POST ['premission_name'];<br>         $price = 0.01;<br>                                                                                                                                                                                                                                   $product_id  =                                      $ product         $premission_name = $prodect_id;<br> ​​​​//Start processing<br>         $input = new WxPayUnifiedOrder ();<br>         $input->SetBody ( "xxxx---" . $premission_name );<br>          $input->SetAttach ( "xxxxx-Attach" );<br>         $input->SetOut_trade_no ( WxPayConfig::MCHID . date ( "YmdHis" ) );<br>          $input->SetTotal_fee ( $price * 100 );<br>         $input->SetTime_start ( date ( "YmdHis" ) );<br>         $input->SetTime_expire ( date ( "YmdHis", time () + 600 ) );<br>          $input->SetGoods_tag ( "xxx-tag" );<br>          $input->SetNotify_url ( "http://xxxx.com/wxtest/index.php/home/Index/notify" );<br>         $input->SetTrade_type ( "NATIVE" );<br>         $input->SetProduct_id ( rand ( 4, 8 ) );<br>         $result = $notify->GetPayUrl ( $input );<br>         $url2 = $result ["code_url"];<br>              // Generate QR code<br> ​​​​error_reporting (E_ERROR);<br> Import ( "@.Controller.WxPay.PHPQRCODE" );<br> ​ ​ ​ $url = urldecode ($url2);<br>         QRcode::png ( $url );<br>} }Example code for WeChat payment callback processing: /**<br> * @Function description: WeChat payment callback processing<br> *                                                                                                                  * * @Time 2016-9-22 3:41:59 pm<br> ​​*/<br> Public function notify() {<br> ​​​​//Get WeChat callback data<br>         $notifiedData = $GLOBALS ['HTTP_RAW_POST_DATA'];<br> ​​​​//Load related classes<br> Import ( "@.Controller.WxPay.WxPayNativePay" );<br> Import ( "@.Controller.WxPay.WxPayData" );<br> Import ( "@.Controller.WxPay.WxPayNotify" );<br> Import ( "@.Controller.WxPay.PayNotifyCallBack" );<br>         $xml_to_arr = WxPayDataBase::FromXml_4_babbage ( $notifiedData );<br> ​​​​//Convert to array and write to cache<br> ​​​​F ("wx_notified_data", $xml_to_arr);<br>              // Let’s also write the xml prototype into xml<br> ​​​​F ("wx_notified_data_xml", $notifiedData);<br> ​​​​<br> ​​​​//Return payment status value to WeChat<br>         $notify = new PayNotifyCallBack ();<br>                                 // Return status <br>          $notify->Handle ( false );<br> }<br>Hope this can be helpful to colleagues with weak skills like me

wxpay4tp.zip thinkphp3.2.3 WeChat payment_scan code payment_with callback( 1.25 MB Download: 8 times )

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn