PHP Micro-Credit Payment example Analysis _php example

Source: Internet
Author: User
Tags openid

This article for you to share the PHP micro-letter payment examples, including PHP micro-letter Payment source code, PHP micro-letter refund source, PHP micro-letter Payment interface for your reference, the specific content as follows

1.JSapi Payment Demo (click in micro-letter client)

<?php/** * JS_API Payment Demo * ==================================================== * in the micro-letter browser to open the H5 page in the implementation of JS adjustment to pay.
 interface input Output data format is JSON. * Successful adjustment of the payment requires three steps: * Step 1: Web page authorization get user OpenID * Step 2: Use the unified payment interface, get prepay_id * Step 3: Use JSAPI to adjust Payment/include_once (".
 
 /wxpaypubhelper/wxpaypubhelper.php ");

 Use the Jsapi interface $jsApi = new Jsapi_pub (); ========= Step 1: Web page authorization to obtain the user openid============//via code to obtain OpenID if (!isset ($_get[' code ')) {//Trigger micro-letter return code Code $URL = $jsApi-&
 Gt;createoauthurlforcode (Wxpayconf_pub::js_api_call_url); 
 Header ("Location: $url");
 }else {//Get code code to get OpenID $code = $_get[' code '];
 $jsApi->setcode ($code);
 $openid = $jsApi->getopenid ();
 
 //========= Step 2: Use the unified payment interface to obtain prepay_id============//using the Unified Payment interface $unifiedOrder = new Unifiedorder_pub (); IGN has been filled in, the merchant does not need to fill in $unifiedOrder->setparameter ("OpenID", "$openid"); the product description $unifiedOrder->setparameter ("Body", " Contribute a penny ");/Product Description/Custom order number, here for example $timeStamp = time (); $out _trade_no = wxpayconf_pub::appid. "
 $timeStamp "; $unifiedOrder->setparameter ("Out_trade_no", "$out _trade_no");//Merchant Order number $unifiedOrder->setparameter ("Total_ Fee "," 1 ")//Total amount $unifiedOrder->setparameter (" Notify_url ", wxpayconf_pub::notify_url);//notification address $unifiedOrder-> Setparameter ("Trade_type", "JSAPI")//transaction type//non-required, the merchant may fill in the actual situation by filling//$unifiedOrder->setparameter ("sub_mch_id", " XXXX ");//Merchant number//$unifiedOrder->setparameter (" Device_info "," XXXX ");//device number//$unifiedOrder->setparameter (" Attach "," xxxx ")//Additional data//$unifiedOrder->setparameter (" Time_start "," xxxx "),//Transaction start time//$unifiedOrder-> Setparameter ("Time_expire", "xxxx");//transaction end time//$unifiedOrder->setparameter ("Goods_tag", "xxxx");//mark of goods//$ Unifiedorder->setparameter ("OpenID", "xxxx");//user identification//$unifiedOrder->setparameter ("product_id", "xxxx");
 Product ID $prepay _id = $unifiedOrder->getprepayid (); ========= Step 3: Use Jsapi to adjust payment ============ $jsApi->setprepayid ($prePAY_ID);
 $jsApiParameters = $jsApi->getparameters ();

 echo $jsApiParameters;?>

2.native Payment mode one demo (static link two-dimensional code with micro-scan)

 <?php/** * Native (native) payment mode one demo * ==================================================== * die
 Type one: The Merchant builds the link two-dimensional code by the fixed form, the user sweeps the code after the micro-letter * will ProductID and the user OpenID sends to the merchant to set up the link, the merchant receives * requests to generate the order, the call Unified payment interface orders submits to the micro-letter, the micro-letter will return * to
* The two-dimensional code corresponding to this routine is generated by native_call_qrcode.php; * This routine corresponds to a response service of native_call.php; * need both to work together. * * Include_once (".

 /wxpaypubhelper/wxpaypubhelper.php "); 
 
 Set static link $nativeLink = new nativelink_pub (); Set static link parameters//set Required parameters//appid has been filled out, the merchant does not need to fill in the//mch_id has filled in, the merchant does not need to fill out the duplicate//noncestr has filled in, the merchant does not need to fill in the duplicate//time_stamp has filled, the merchant does not need to fill in the duplicate//sign No need to repeat $product _id = wxpayconf_pub::appid. " Static "//Custom Commodity ID $nativeLink->setparameter (" product_id "," $product _id ");//Product ID//Get link $product _url = $

 Nativelink->geturl ();
 Use the short link transform interface $shortUrl = new Shorturl_pub ();
 
"Long_url", "$product _url");//url link//Get short link $CODEURL = $shortUrl->getshorturl (); ?> 

3.native Payment Mode two demo (dynamic link two-dimensional code with micro-scan)

 <?php/** * Native (native) payment-mode two-demo * ==================================================== * Merchants generate orders, first call the unified payment interface to get code
 _url, * This URL generates a two-dimensional code, the user swept the code after the payment. * * * */include_once (".

 /wxpaypubhelper/wxpaypubhelper.php ");
 
 Use the unified payment interface $unifiedOrder = new Unifiedorder_pub ();
 IGN has been filled out, the merchant does not need to fill in $unifiedOrder->setparameter ("Body", "Contribution a Penny");//Product Description/Custom order number, here for example $timeStamp = time (); $out _trade_no = wxpayconf_pub::appid. "
 $timeStamp "; $unifiedOrder->setparameter ("Out_trade_no", "$out _trade_no");//Merchant Order number $unifiedOrder->setparameter ("Total_ Fee "," 1 ")//Total amount $unifiedOrder->setparameter (" Notify_url ", wxpayconf_pub::notify_url);//notification address $unifiedOrder-> Setparameter ("Trade_type", "NATIVE")//transaction type//non-required, the merchant may fill in the actual situation by filling//$unifiedOrder->setparameter ("sub_mch_id", " XXXX ")//Merchant number//$unifiedOrder->setparameter (" Device_info "," XXXX ");//$unifiedOrder->setparAmeter ("Attach", "xxxx");//Additional data//$unifiedOrder->setparameter ("Time_start", "xxxx");//Trading start time/$unifiedOrder- >setparameter ("Time_expire", "xxxx");//transaction end time//$unifiedOrder->setparameter ("Goods_tag", "xxxx");//mark of goods//$ Unifiedorder->setparameter ("OpenID", "xxxx");//user identification//$unifiedOrder->setparameter ("product_id", "xxxx");
 
 Product ID//Get Uniform payment interface Result $unifiedOrderResult = $unifiedOrder->getresult (); The merchant set up the corresponding process flow according to the actual situation if ($unifiedOrderResult ["return_code"] = = "FAIL") {//merchant to increase the process flow echo "Communication error:". $unifiedOrderResult [' Return_msg ']. "
 <br> "; } elseif ($unifiedOrderResult ["result_code"] = = "FAIL") {//merchant to increase its handling process echo "error code:". $unifiedOrderResult [' Err_code ']. "
 <br> "; echo "Error code Description:". $unifiedOrderResult [' Err_code_des ']. "
 <br> ";
 ElseIf ($unifiedOrderResult ["Code_url"]!= NULL) {//From the unified payment interface to the Code_url $code _url = $unifiedOrderResult ["Code_url"];

Merchants to increase their own process//...}

 ?>

4. Payment Query Interface Demo

<?php/** * Order Enquiry-demo * ==================================================== * This interface provides inquiries for all micro-credit payment orders.
 * When payment notification is handled abnormally or lost, the merchant can inquire the order payment status through the interface. * * * */include_once (".
 
 /wxpaypubhelper/wxpaypubhelper.php ");
 Refund Order number if (!isset ($_post["Out_trade_no")) {$out _trade_no = "";

 }else{$out _trade_no = $_post["Out_trade_no"];
 Use order query Interface $orderQuery = new Orderquery_pub (); Setparameter ("Out_trade_no", "$out _trade_no"), or merchant order number//non-required parameters, the merchant may fill in the actual situation by filling//$orderQuery->setparameter ("Sub_mch _id "," xxxx ")//Sub Merchant number//$orderQuery->setparameter (" transaction_id "," xxxx ");//micro-letter order number//Get order query Results $orderQueryResult =
 
 $orderQuery->getresult (); The merchant sets the corresponding processing flow according to the actual situation, here only for example if ($orderQueryResult ["return_code"] = = "FAIL") {echo "Communication error:". $orderQueryResult [' Return_ Msg ']. "
 <br> "; } elseif ($orderQueryResult [result_code] = = "FAIL") {Echo error code: ". $orderQueryResult [' Err_code ']." <bR> "; echo "Error code Description:". $orderQueryResult [' Err_code_des ']. "
 <br> "; else{echo "Transaction status:". $orderQueryResult [' trade_state ']. "
 <br> "; echo "Device number:". $orderQueryResult [' Device_info ']. "
 <br> "; echo "User id:". $orderQueryResult [' OpenID ']. "
 <br> "; Echo "is concerned about the public account:". $orderQueryResult [' Is_subscribe ']. "
 <br> "; echo "Transaction type:". $orderQueryResult [' Trade_type ']. "
 <br> "; echo "Payment Bank:". $orderQueryResult [' Bank_type ']. "
 <br> "; echo "Total amount:". $orderQueryResult [' Total_fee ']. "
 <br> "; echo "Cash coupon Amount:". $orderQueryResult [' Coupon_fee ']. "
 <br> "; echo "Currency type:". $orderQueryResult [' Fee_type ']. "
 <br> "; echo "Micro Letter Payment order Number:". $orderQueryResult [' transaction_id ']. "
 <br> "; echo "Merchant Order Number:". $orderQueryResult [' Out_trade_no ']. "
 <br> "; echo "Merchant packet:". $orderQueryResult [' Attach ']. "
 <br> "; echo "Payment completion Time:". $orderQueryResult [' Time_end ']. "
 <br> "; }//Merchant to increase the processing flow//...?

 >

5. Billing Interface Demo

<?php/** * Billing Interface Demo * ==================================================== * merchant can download the historical transaction list through this interface. * * Include_once (".

 /wxpaypubhelper/wxpaypubhelper.php ");
 The statement date if (!isset ($_post["Bill_date"])) {$bill _date = "20140814";
 
 else{$bill _date = $_post["Bill_date"];
 Use the Billing interface $downloadBill = new Downloadbill_pub (); T;setparameter ("Bill_date", "$bill _date");/$downloadBill->setparameter ("Bill_type", "all");//bill type// Non-required parameters, the merchant can be selected according to the actual situation//$downloadBill->setparameter ("Device_info", "XXXX");//The interface result of the equipment number//Statement $downloadBillResult = $dow
 Nloadbill->getresult ();
 
 echo $downloadBillResult [' Return_code '];
 if ($downloadBillResult [' return_code '] = = "FAIL") {Echo communication error: ". $downloadBillResult [' return_msg '];
 }else{print_r (' <pre> '); echo "" To the billing Details "". "
 </br> ";
 Print_r ($downloadBill->response);
 Print_r (' </pre> '); }
 }
 
?>

 

6. Refund Interface Demo

<?php/** * Refund Request Interface-demo * ==================================================== * NOTE: A partial refund of the same bill requires the same order number and a different * out_ Refund_no. A refund fails to be resubmitted after the original * Out_refund_no is used.
The total refund amount cannot exceed the actual amount of money paid by the user (current * Voucher amount cannot be refunded). * * Include_once (".

 /wxpaypubhelper/wxpaypubhelper.php ");
 Enter the order number to be refunded if (!isset ($_post["Out_trade_no")) | |!isset ($_post["Refund_fee"]) {$out _trade_no = "";
 $refund _fee = "1";
  }else{$out _trade_no = $_post["Out_trade_no"];
 $refund _fee = $_post["Refund_fee"]; Merchant refund number, merchant custom, here for example $out _refund_no = "$out _trade_no".
 $time _stamp ";
 
 The total amount must correspond to the order number Out_trade_no, the total amount of all orders in the demo is 1 minutes $total _fee = "1";
 Use the refund interface $refund = new Refund_pub (); Out_trade_no "," $out _trade_no ");/merchant Order number $refund->setparameter (" Out_refund_no "," $out _refund_no "); Refund->setparameter ("Total_fee", "$total _fee");//Total Amount $refund->setparameter ("Refund_fee", "$refund _fee");
Refund Amount $refund->setparameter ("op_user_id", Wxpayconf_pub::mchid) or operator//non required parameters, the merchant can fill in//$refund according to the actual situation->setparameter ("sub_mch_id", "xxxx");//Merchant number//$refund->setparameter ("Device_info", "xxxx");//device number//$refund->setparameter ("
 
 transaction_id "," XXXX ")//micro-letter order number//Call result $refundResult = $refund->getresult (); The merchant sets the corresponding processing flow according to the actual situation, here only for example if ($refundResult ["return_code"] = = "FAIL") {echo "Communication error:". $refundResult [' return_msg ']. "
 <br> "; else{echo "Business results:". $refundResult [' Result_code ']. "
 <br> "; echo "Error code:". $refundResult [' Err_code ']. "
 <br> "; echo "Error code Description:". $refundResult [' Err_code_des ']. "
 <br> "; echo "Public account ID:". $refundResult [' AppID ']. "
 <br> "; echo "Merchant number:". $refundResult [' mch_id ']. "
 <br> "; echo "Sub merchant Number:". $refundResult [' sub_mch_id ']. "
 <br> "; echo "Device number:". $refundResult [' Device_info ']. "
 <br> "; echo "Signature:". $refundResult [' sign ']. "
 <br> "; echo "Micro-letter order Number:". $refundResult [' transaction_id ']. "
 <br> "; echo "Merchant Order Number:". $refundResult [' Out_trade_no ']. "<br> "; echo "Merchant Refund Number:". $refundResult [' Out_refund_no ']. "
 <br> "; echo "micro-credit Refund number:". $refundResult [' refund_idrefund_id ']. "
 <br> "; echo "Refund Channel:". $refundResult [' Refund_channel ']. "
 <br> "; echo "Refund amount:". $refundResult [' Refund_fee ']. "
 <br> "; echo "Cash voucher refund Amount:". $refundResult [' Coupon_refund_fee ']. "
 <br> ";

 }}?>

7. Refund Query Interface Demo

<?php/** * Refund Request Interface-demo * ====================================================

 /wxpaypubhelper/wxpaypubhelper.php ");
 The order number to query if (!isset ($_post["Out_trade_no"])) {$out _trade_no = "";
 
 }else{$out _trade_no = $_post["Out_trade_no"];
 Use the refund query interface $refundQuery = new Refundquery_pub (); Setparameter ("Out_trade_no", "$out _trade_no");//Merchant Order number//$refundQuery->setparameter ("Out_refund_no", "XXXX"); Merchant Refund Number//$refundQuery->setparameter ("refund_id", "XXXX");//micro-Credit Refund number//$refundQuery->setparameter ("Transaction _id "," xxxx ");//micro-Credit Refund number//non-required parameters, the merchant can fill in according to the actual situation//$refundQuery->setparameter (" sub_mch_id "," xxxx ");//Sub Merchant No.//$ Refundquery->setparameter ("Device_info", "XXXX");//Refund Query interface Results $refundQueryResult = $refundQuery->
 
 GetResult (); The merchant sets the corresponding processing flow according to the actual situation, here only for example if ($refundQueryResult ["return_code"] = = "FAIL") {echo "Communication error:". $refundqueryresult[' return_msg ']. "
 <br> "; else{echo "Business results:". $refundQueryResult [' Result_code ']. "
 <br> "; echo "Error code:". $refundQueryResult [' Err_code ']. "
 <br> "; echo "Error code Description:". $refundQueryResult [' Err_code_des ']. "
 <br> "; echo "Public account ID:". $refundQueryResult [' AppID ']. "
 <br> "; echo "Merchant number:". $refundQueryResult [' mch_id ']. "
 <br> "; echo "Sub merchant Number:". $refundQueryResult [' sub_mch_id ']. "
 <br> "; echo "Device number:". $refundQueryResult [' Device_info ']. "
 <br> "; echo "Signature:". $refundQueryResult [' sign ']. "
 <br> "; echo "Micro-letter order Number:". $refundQueryResult [' transaction_id ']. "
 <br> "; echo "Merchant Order Number:". $refundQueryResult [' Out_trade_no ']. "
 <br> "; echo "Refund Number of Pens:". $refundQueryResult [' Refund_count ']. "
 <br> "; echo "Merchant Refund Number:". $refundQueryResult [' Out_refund_no ']. "
 <br> "; echo "micro-credit Refund number:". $refundQueryResult [' refund_idrefund_id ']. "
 <br> "; echo "Refund Channel:". $refundQueryResult [' Refund_channel ']. "
 <br> "; echo "Refund amount:". $refundQueryResult [' Refund_fee ']. "
 <br> "; echo "Cash voucher refund Amount:". $refundQueryResult [' Coupon_refund_fee ']."
 <br> "; echo "Refund Status:". $refundQueryResult [' Refund_status ']. "
 <br> ";

 }}?>

Micro-letter Payment Source Download

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.