The JS listening payment button in html--triggering Ajax calls to PHP backend--the resulting JSON Data---given to Android native processing

Source: Internet
Author: User
<span id="Label3"></p><pre><pre>01</pre></pre><pre>var pay_status = new Object ();<br>$ (". sure_pay"). on ("touchstart", function () {<br><br>var order_id = $ (' #order_id '). Val ();<br><br><br>Paylinkshape ("showshape");<br>var paytype=1;//is paid by default and is used to store the payment symbol logo<br>/* Click to get payment method start*/<br>$ ('. Paybox input '). on (' ifchecked ', function (event) {<br>if (event.type = = "ifchecked") {<br>clsname=$ (this). attr ("class");<br>}<br>})<br>/* Click to get payment method end*/<br>Switch (clsname)<br>{<br>Case "weix":<br>paytype=1;<br>Break<br>Case "zfb":<br>paytype=2;<br>Break<br>Case ' Company ':<br>paytype=0;<br>Break<br>}<br><br>Console.log (' Clsname = = ');<br>Console.log (clsname);<br>Console.log (' order_id = ' +order_id);<br>$.ajax ({<br>Url: "/order/pay_order_wx?order_id=" +order_id,<br>Type: ' GET ',<br>Data: "{}",<br>DataType: "json",<br>Success:function (jsonpayinfo) {<br>Console.log (' Success = = ');<br>Console.log (jsonpayinfo);<br>if (jsonpayinfo.return_code = = ' SUCCESS ' && jsonpayinfo.result_code = = ' SUCCESS ')<br>{<br>Jsonpayinfo=json.stringify (jsonpayinfo);<br>Console.log (jsonpayinfo);<br>Paylinkshape ();<br>var u = navigator.useragent;<br>Tripmobile.trippay (paytype,jsonpayinfo);<br>If (u.indexof (' Android ') >-1 | | u.indexof (' Linux ') >-1) {<br>Android phone<br>Tripmobile.trippay (paytype,jsonpayinfo);<br>Console.log (paytype);<br>Console.log (jsonpayinfo);<br>} else if (u.indexof (' iPhone ') >-1) {<br>Apple phone<br>Jakilllog (paytype,jsonpayinfo);<br>}<br>}else{<br>Console.log (' come in here ');<br>Return false;<br>}<br>}, error:function (xmlhttprequest, textstatus, Errorthrown) {<br>Console.log (' Error + + + ');<br>Console.log (xmlhttprequest);<br>Console.log (textstatus);<br>Console.log (errorthrown);<br><br><br>}<br>});<br><br>})</pre><pre><br><br><br><br><br><br>02 Call Payment<br>Public Function Pay_order_wx ($order _id)<br>{<br><br>$orderModel = M ("order");<br>$get _data = I (' get. ');<br><br>$where [' order_id '] = $get _data[' order_id ');<br>$orderinfo = $orderModel->where ($where)->find ();<br><br>Require_once (app_path. /thinkphp/thinkphp/library/vendor/wxpay/lib/wxpay.api.php ");<br>Require_once (app_path. /thinkphp/thinkphp/library/vendor/wxpay/lib/wxpay.config.php ");<br>Require_once (app_path. /thinkphp/thinkphp/library/vendor/wxpay/lib/wxpay.data.php ");<br>Require_once (app_path. /thinkphp/thinkphp/library/vendor/wxpay/lib/wxpay.exception.php ");<br>Require_once (app_path. /thinkphp/thinkphp/library/vendor/wxpay/jsapipay.php ");<br><br>$tools = new Jsapipay ();<br>$openId = $tools->getopenid ();<br>②, Unify the Order<br><br>$input = new Wxpayunifiedorder ();<br>$input->setbody (' Travel expenses ');<br>$input->setattach ("test");<br>$input->setout_trade_no ($orderinfo [' order_num '].date ("ymdhis"));//8-digit order number plus 14-bit time<br><br>if (trip_mode = = ' DEV ' | | Trip_mode = = ' TEST ') {<br>$input->settotal_fee ("1");//development environment, and test environment. default payment $0.01<br>}else{<br>$input->settotal_fee ($orderinfo [' Order_true_total_money '] * 100); Payment to be divided into Units.<br>}<br>Our database is 100.16 Yuan. will be turned into 100.16 points<br><br>$input->settime_start (date ("ymdhis"));<br>$input->settime_expire (date ("ymdhis", time () + 600));<br>$input->setgoods_tag ("test");<br><br>$input->setnotify_url ("http://{$_server[' http_host ']}/api/wxpay/on_wxpay_complete.html");<br>$input->settrade_type ("APP");<br>$order = Wxpayapi::unifiedorder ($input);<br><br>$timeStamp = Time ();<br>$returnorder [' AppID '] = "wx9xxxxxx4f7dde7";<br>$returnorder [' Partnerid '] = "13999999991";<br>$returnorder [' noncestr '] = MD5 ($order [' nonce_str ']);<br>$returnorder [' Timestamp '] = $timeStamp;<br>$returnorder [' Prepayid '] = $order [' prepay_id '];<br>$returnorder [' Package '] = "sign=wxpay";<br><br>Signature Step one:<br>Ksort ($returnorder);<br>$sign = "";<br>foreach ($returnorder as $k = $v)<br>{<br>If ($k! = "sign") {<br>$SIGN. = $k. "=" . $v. "&";<br>}<br>}<br>$sign = Trim ($sign, "&");<br><br>Signature Step two: add key after string<br>$sign = $sign. "&key=". wxpayconfig::key;<br>$sign = $sign. "&key=". ' Xxxxxxxxxxx ';<br><br>Signature Step three: MD5 Encryption<br>$sign = MD5 ($sign);<br>Signature step Four: all characters to uppercase<br>$sign = Strtoupper ($sign);<br>$returnorder [' Sign '] = $sign;<br><br>$returnorder [' Return_code '] = $order [' return_code '];<br>$returnorder [' return_msg '] = ' OK ';<br>$returnorder [' Result_code '] = $order [' result_code '];<br>D (' Tlog ')->log ("payment order orderid=". $order _id. ' Result '. json_encode_ex ($order));<br>$this->ajaxreturn ($returnorder, ' JSON ');<br><br>}<br><br><br>03 Receiving callbacks</pre><pre>Public Function On_wxpay_complete ()<br>{<br>$info = $_request;<br><br>If (app_debug) \think\log::write (' wxnotify:raw_post: '. $GLOBALS ["http_raw_post_data"], ' DEBUG ');<br> <br>$rowpost = $GLOBALS ["http_raw_post_data"];<br> <br>Vendor (' Xmlparser.xml ', ' ', '. class.php ');<br> <br>$QR = Xml_unserialize ($rowpost);<br><br>Mylog1 (' $QR = = '. json_encode_ex ($qr));<br><br>Log logs to log all Third-party notification messages<br>$curtime = Date (' Ymd h:i:s ');<br>$ordernumber = $QR [' xml '] [' out_trade_no '];<br>$ordernumber = substr ($qr [' xml '] [' out_trade_no '], 0, 12);<br>File_put_contents (C (' logpath_order_nitify '). " /wxpay_{$ordernumber}.txt "," \n\n$curtime \ n ". json_encode_ex ($qr), file_append);<br> <br>/*<br>Array (1) {<br>["xml"] = + Array (17) {<br>["appid"] = + String () "wx9999999dde7"<br>["attach"] = + String (4) "test"<br>["bank_type"] + = string (3) "CFT"<br>["cash_fee"] = + String (1) "1"<br>["fee_type"] = + String (3) "CNY"<br>["is_subscribe"] + = string (1) "N"<br>["mch_id"] = + String (10) "1346077501"<br>["nonce_str"] = + String (+) "ermeg0d01gv7k4aqppwrmtqfn1yohgy0"<br>["openid"] + string (+) "ok4np999999b7x90jmwdc"<br>["out_trade_no"] = + String (26) "20160524010520160526193042"<br>["result_code"] = + String (7) "SUCCESS"<br>["return_code"] = + String (7) "SUCCESS"<br>["sign"] = + String (+) "0ecb9999999df9b859c45"<br>["time_end"] = + String (14) "20160526193052"<br>["total_fee"] = + String (1) "1"<br>["trade_type"] = + String (3) "APP"<br>["transaction_id"] = + String (28) "4099999999993752"<br>}<br>}<br>*/<br> <br>If (' SUCCESS ' = = $QR [' xml '] [' result_code '] && ' SUCCESS ' = = $QR [' xml '] [' return_code '])<br>{<br> <br>Payment success<br><br><br><br><br></pre><pre><pre><br><br></pre></pre><p><p>The JS listening payment button in html--triggering Ajax calls to PHP backend--the resulting JSON Data---given to Android native processing</p></p></span>

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.