Home >Backend Development >PHP Tutorial >php handles WeChat bills
The content introduced in this article is about php processing WeChat bills. It has a certain reference value. Now I share it with you. Friends in need can refer to it. It has a certain reference value. Now Share it with everyone, friends in need can refer to
Recently I have to do payment reconciliation, that is, check whether the third-party payment and the bill in the database correspond one-to-one, which involves the processing of WeChat statement, and the WeChat bill interface returns The result is a string similar to the following:
The function that the program needs to implement is to extract the effective information of each order from this string. The reference code is as follows:
function deal_wechat_return_result($reponse) { $result = array(); $reponse = str_replace(","," ",$reponse); $reponse = explode("`",$reponse); $total_order_count =( count($reponse) - 6 ) / 24; for($i = 0; $i< $total_order_count; $i++) { $base_index = 24 * $i; $result[$reponse[$base_index + 7]] = array( 'wechat_order_no' => $reponse[$base_index + 6], 'order_count' => $reponse[$base_index + 13], 'order_discount' => $reponse[$base_index + 23] ); } return $result; }
## The main idea is that the format of the result returned by WeChat bill is fixed. You can use '`' to split the string. Then every 24 fields are the description information of an order, and the last 6 fields are the summary information of the bill. Therefore, the entire bill can be traversed through the for loop. The code only takes the fields I need. If other fields are needed, I can add them by myself according to this format.
The code still needs to be improved in the following points:
1. It does not consider the case where the string is particularly large, which may cause the memory allocated by the php process to be exhausted. For ordinary merchant orders, every day It is sufficient when the trading volume is not particularly large.
2. By default, the format returned by WeChat is fixed. In fact, dynamic matching can be performed based on the head and tail of the string returned by WeChat.
Related recommendations:
php method for processing URLs with Chinese charactersphp method for processing form upload filesPHP processing Excel table instance methodThe above is the detailed content of php handles WeChat bills. For more information, please follow other related articles on the PHP Chinese website!