This article mainly introduces how to obtain alarm notifications in WeChat payment, and attaches example codes for reference. I hope I can help those who develop WeChat Pay.
1. Alarm notification
In order to promptly notify merchants of abnormalities and improve merchants’ service quality on the WeChat platform. The WeChat backend will push alarm notifications to merchants, including delivery delays, call failures, notification failures, etc. The notification address is the alarm notification URL filled in by the merchant when applying for payment, which can be found in "Public Platform - Service - Service Center - Merchant Functions - Merchant Basic Information - Alarm Notification URL" can be viewed. After receiving the alarm notification, merchants need to repair the problems mentioned in it as soon as possible to avoid affecting online operations.
The postData received by the alarm notification URL will also contain xml data in the following format:
<xml> <AppId><![CDATA[wxf8b4f85f3a794e77]]></AppId> <ErrorType>1001</ErrorType> <Description><![CDATA[错识描述]]></Description> <AlarmContent><![CDATA[错误详情]]></AlarmContent> <TimeStamp>1393860740</TimeStamp> <AppSignature><![CDATA[f8164781a303f4d5a944a2dfc68411a8c7e4fbea]]></AppSignature> <SignMethod><![CDATA[sha1]]></SignMethod> </xml>
2. Program reception
Now is the implementation of the alarm.php function, which can be obtained by imitating the WeChat basic interface SDK. Write detailed information to the database or other storage
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); logger("错误类型:".$postObj->ErrorType."错识描述:".$postObj->Description."错误详情:".$postObj->AlarmContent); //日志记录 function logger($log_content) { $max_size = 100000; $log_filename = "log.xml"; if(file_exists($log_filename) and (abs(filesize($log_filename)) > $max_size)){unlink($log_filename);} file_put_contents($log_filename, date('H:i:s')." ".$log_content."\r\n", FILE_APPEND); }
Related recommendations:
WeChat refund function example of PHP WeChat payment development
Detailed explanation of Thinkphp integrating WeChat payment function
10 recommended courses on WeChat payment development
The above is the detailed content of Alarm notification example of WeChat payment. For more information, please follow other related articles on the PHP Chinese website!