Home  >  Article  >  Backend Development  >  Alarm notification example of WeChat payment

Alarm notification example of WeChat payment

*文
*文Original
2017-12-29 18:15:231882browse

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:


  
  1001
  
  
  1393860740
  
  

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!

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