PHP processing WeChat Payment callback Change Order payment status code

Source: Internet
Author: User
Tags cdata md5 encryption php server
This article brings you the content is about PHP server app payment callback verification signature Change Order payment status, there is a certain reference value, the need for friends can refer to, I hope to help you.

<?php//Processing Payment Callback $time = time ();  $testxml = file_get_contents ("Php://input");       Receive payment success information sent by//file_put_contents (' D:\webroot\xianyijie\JK\weixin.txt ', $testxml);       $result = Xmldataparse ($testxml); File_put_contents ("D:\webroot\xianyijie\JK\weixin.txt", Json_encode ($result). " \ r \ n ", file_append);    Write information to TXT file for payment backup $sign _return = $result [' sign '];            If successfully returned if ($result [' return_code '] = = ' SUCCESS ' && $result [' result_code '] = = ' SUCCESS ') {            $key = "Merchant Key key";            unset ($result [' sign ']);   $sign = Appgetsign ($result, $key);  if ($sign = = $sign _return)//Verify signature {//This is the SQL operation after successful verification//If the operation is successful return "<xml><return_code><! [cdata[success]]></return_code> <return_msg><!                [cdata[ok]]></return_msg> </xml> ";   If the operation fails, return "fail";      }      }/* * format parameter formatted as URL parameter generate signature sign*/function appgetsign ($OBJ, $appwxpay _key) {foreach ($Obj as $k + $v) {    $Parameters [$k] = $v;    }//Signature step one: sorted by dictionary order parameter Ksort ($Parameters);    $String = Formatbizqueryparamap ($Parameters, false); Echo ' "string1" '. $String. '    </br> '; Signature Step Two: Add key if ($appwxpay _key) {$String = $String after the String.        &key= ". $appwxpay _key; }//echo "" string2 "". $String. "    </br> ";    Signature Step Three: MD5 encryption $String = MD5 ($String); echo "String3" ". $String."    </br> ";    Signature Step four: All characters to uppercase $result _ = Strtoupper ($String); echo "Result". $result _. "    </br> ";  return $result _;  }//xml Format Data parsing functions function Xmldataparse ($data) {$xml = Simplexml_load_string ($data, null,libxml_nocdata);  $array =json_decode (Json_encode ($xml), true); return $array; }?>

Related articles recommended:

PHP's curl in the post mode and get way request code

About PHP Intermediate key content parsing

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.