Schematic diagram of an asynchronous operation code for online Banking

Source: Internet
Author: User

1. With regard to the operation of asynchronous feedback, this is necessary because sometimes, if the user suddenly breaks the net or something, it will not result in data anomalies, no feedback to the successful information.
So this operation needs to be asynchronous.
If the normal situation, is to take the process of synchronization, and then the net will be around every three minutes feedback an asynchronous request, only the feedback value is true to modify the order information, the basic value and synchronization are similar.

2. Learn about the written operation.
① in the main.php file, configure an asynchronous return path

② in the Unionpayproxy.php folder, add the URL of the asynchronous notification on the original basis and initialize it to the Remark2 field.

③ in the Unionpayservice page, the Remark2 field is initialized individually, if any, is

if($key‘remark2‘){    //在remark2这个字段配置一个异步通知的url注意在value里面要加上中括号    $sHtml.=‘<input  type="hidden"  name="remark2" value="[url:=‘.$val.‘]">‘;}

To add the above fields, the URL there to add brackets, be sure to follow the above format to assign values

④ add a corresponding method in the directory where I correspond to the asynchronous notification, and the exact wording is the same as the synchronization
/**
* UnionPay returns the display page asynchronously
* @desc asynchronous notification to pay "statement"
* @return Boolean
* @author Xcz <2015-7-28>
*
*/
function Actionunionpaynoticereturn () {
$unionpay = Yii::app ()->unionpay;

Functionhelper::sendmail ("[email protected]", "Zongzi test", "Zongzi test", Print_r ($_post,true));//exit; $key = ' joyowoyaobaohuhao990 ';//After landing in the navigation bar above may find "data management", in the data management level two navigation bar has "MD5 key settings" $return _array = $_post; $v _oid = Trim ($_post[' V  _oid ']);//v_oid order Number $v_pmode = Trim ($_post[' v_pmode ') sent by merchant;//payment Method (String) $v _pstatus = Trim ($_post[' v_pstatus '));// Payment Status: 20 (Payment succeeded), 30 (Payment failed) $v _pstring = Trim ($_post[' v_pstring ')),//Payment result information: Payment completed (when v_pstatus=20); failure reason (when v_pstatus=30, $v _amount = Trim ($_post[' v_amount ');//Order actual payment amount $remark1 = Trim ($_post[' remark1 '));//Memo Field 1$REMARK2 = Trim ($_post [' REMARK2 ']); /Memo field 2//MD5 checksum value $v_md5str = Trim ($_post[' v_md5str '); $v _moneytype = Trim ($_post[' v_moneytype ');//recalculate MD5 value $ md5string = Strtoupper (MD5 ($v _oid. $v _pstatus. $v _amount. $v _moneytype. $key));//Determine the return information, if the payment is successful, and the payment result is credible, then do further if ($    V_md5str = = $md 5string) {//Payment Status: 20 (successful payment);//30 (Payment failed)//payment successful, can be processed logically!    Logical processing of merchant systems (e.g. judging amount, judging payment status, updating order status, etc.) ...;    if ($v _pstatus = = 20) {//Payment Status: 20 (payment succeeded); 30 (Payment failed)    Payment is successful and can be processed logically!        Logical processing of merchant systems (e.g. judging amount, judging payment status, updating order status, etc.) ...;        er = Array ();        er = Ordermodel::model ()->find (' Order_code=:order_code ', Array (' order_code ' = = $v _oid));        $transaction = Yii::app ()->db->begintransaction ();            try {Ordermodel::model ()->updateorderstatus ($v _oid, $v _amount, Ordermodel::servicecomplet);            er _social_detail_model = Ordersocialdetailmodel::model ()->findall (' order_id= '. $v _oid);                    if (!empty (er _social_detail_model)) {foreach (er _social_detail_model as $value) {                    $value->pay_status = 1;                    $value->paid_status = 1;                    $value->paid_time = Date (' y-m-d h:i:s ', Time ());                    $value->service_status = 3;                    $value->pay_time = Date (' y-m-d h:i:s ', Time ());                $value->update ();        }} $transaction->commit ();}catch (Exception $e) {//If the operation fails, data rollback $transaction->rollback ();        } yii::app ()->ssoclient->refreshlogininfo ();        Yii::app ()->ssoclient->getlogininfo ();    return true;    }else{return false; } exit ();}

}

⑤ to join in the corresponding place

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Online-Silver Asynchronous operation code

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.