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() {
Example code for WeChat payment callback processing:
Import ( "@.Controller.WxPay.WxPayNativePay" );
$notify = new WxPayNativePay ();
$url1 = $notify->GetPrePayUrl ( "123456789" );
//Mode 2
/**
* Process:
* 1. Call unified ordering, get code_url, and generate QR code
* 2. Users scan the QR code to make payment
* 3. After the payment is completed, the WeChat server will notify you that the payment was successful
* 4. In the payment success notification, you need to check the order to confirm whether the payment is actually successful (see: notify.php)
*/
// $price = $_POST ['price'];
// $prodect_id = $_POST ['prodect_id'];
// $premission_name = $_POST ['premission_name'];
$price = 0.01;
$product_id = $ product $premission_name = $prodect_id;
//Start processing
$input = new WxPayUnifiedOrder ();
$input->SetBody ( "xxxx---" . $premission_name );
$input->SetAttach ( "xxxxx-Attach" );
$input->SetOut_trade_no ( WxPayConfig::MCHID . date ( "YmdHis" ) );
$input->SetTotal_fee ( $price * 100 );
$input->SetTime_start ( date ( "YmdHis" ) );
$input->SetTime_expire ( date ( "YmdHis", time () + 600 ) );
$input->SetGoods_tag ( "xxx-tag" );
$input->SetNotify_url ( "http://xxxx.com/wxtest/index.php/home/Index/notify" );
$input->SetTrade_type ( "NATIVE" );
$input->SetProduct_id ( rand ( 4, 8 ) );
$result = $notify->GetPayUrl ( $input );
$url2 = $result ["code_url"];
// Generate QR code
error_reporting (E_ERROR);
Import ( "@.Controller.WxPay.PHPQRCODE" );
$url = urldecode ($url2);
QRcode::png ( $url );
} }/**
* @Function description: WeChat payment callback processing
* * * @Time 2016-9-22 3:41:59 pm
*/
Public function notify() {
//Get WeChat callback data
$notifiedData = $GLOBALS ['HTTP_RAW_POST_DATA'];
//Load related classes
Import ( "@.Controller.WxPay.WxPayNativePay" );
Import ( "@.Controller.WxPay.WxPayData" );
Import ( "@.Controller.WxPay.WxPayNotify" );
Import ( "@.Controller.WxPay.PayNotifyCallBack" );
$xml_to_arr = WxPayDataBase::FromXml_4_babbage ( $notifiedData );
//Convert to array and write to cache
F ("wx_notified_data", $xml_to_arr);
// Let’s also write the xml prototype into xml
F ("wx_notified_data_xml", $notifiedData);
//Return payment status value to WeChat
$notify = new PayNotifyCallBack ();
// Return status
$notify->Handle ( false );
}
Hope this can be helpful to colleagues with weak skills like me
wxpay4tp.zip( 1.25 MB Download: 8 times )