Home >WeChat Applet >WeChat Development >WeChat payment development alarm notification

WeChat payment development alarm notification

高洛峰
高洛峰Original
2017-02-24 17:07:271654browse

This article introduces how to obtain alarm notifications in WeChat payment.

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

Developed in WeChat payment (1) WeChat payment URL configuration As mentioned in, the alarm notification url is set to

http://www.doucube.com/wxpay/alarm.php

Now is the alarm.php function has been implemented, just imitate the WeChat basic interface SDK to obtain it. Write detailed information to the database or other storage

$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
$postObj = simplexml_load_string($postStr, &#39;SimpleXMLElement&#39;, 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(&#39;H:i:s&#39;)." ".$log_content."\r\n", FILE_APPEND);
}

For more WeChat payment development and alarm notification related articles, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn