Introduction to WeChat payment development statement

Source: Internet
Author: User
Tags openid
Payment is now divided into v2 and v3. the application for payment is v2 before January 1, September 10, 2014, and the application for payment is v3. The paySignKey parameter is not provided for payment in V3. For more information about v2, see other articles by Fang times studio. This article describes payment v3. Note:

Payment is now divided into v2 and v3. the application for payment is v2 before January 1, September 10, 2014, and the application for payment is v3. The paySignKey parameter is not provided for payment in V3. For more information about v2, see other articles by Fang times studio. This article describes payment v3.

I. billing data interface

Payment v3 provides a data interface for billing. the interface used is

Https://api.mch.weixin.qq.com/pay/downloadbill

The request parameters are as follows:

Field name

Variable name

Required

Type

Sample value

Description

Public Account ID

Appid

Yes

String (32)

Wx88888888888888

Assigned public account ID

Merchant ID

Mch_id

Yes

String (32)

1900000109

Merchant ID for payment allocation

Device No.

Device_info

No

String (32)

013467007045764

Pay for the assigned terminal device number. fill in this field and only download the statement of this device number.

Random string

Nonce_str

Yes

String (32)

5k8rjiltkch16cq2502si8znmtm67vs

A random string of no more than 32 characters. Recommendation random number generation algorithm

Signature

Sign

Yes

String (32)

C380BEC2BFD727A4B6845133519F3AD6

Signature. for details, refer to the signature generation algorithm.

Statement date

Bill_date

Yes

String (8)

20140603

Download statement date, in the format of 20140603

Bill type

Bill_type

No

String (8)

ALL

ALL: returns information about ALL orders of the current day. default value:

SUCCESS: return the order successfully paid on the current day

REFUND: returns the REFUND order for the current day

REVOKED: canceled order

The implementation code in the Demo is as follows:

Include_once ("../WxPayPubHelper. php"); // statement date if (! Isset ($ _ POST ["bill_date"]) {$ bill_date = "20150401";} else {$ bill_date = $ _ POST ["bill_date"]; // use the statement interface $ downloadBill = new DownloadBill_pub (); // Set the statement interface parameters // set the required parameter // appid is filled in, the merchant does not need to fill in the // mch_id already filled in, the merchant does not need to fill in again // noncestr already filled in, and the merchant does not need to fill in again // sign already filled in, the merchant does not need to fill in $ downloadBill-> setParameter ("bill_date", "$ bill_date"); // statement date $ downloadBill-> setParameter ("bill_type", "ALL "); // billing type // optional parameters. merchants can select this parameter based on actual conditions. // $ downloadBill-> setParameter ("device_info", "XXXX "); // device No. // $ downloadBill-> setParameter ("device_info", "Fang times Studio 1 "); // device number // statement interface result $ downloadBillResult = $ downloadBill-> getResult (); echo $ downloadBillResult ['return _ Code']; if ($ downloadBillResult ['return _ Code'] = "FAIL") {echo "communication error :". $ downloadBillResult ['return _ msg '];} else {print_r ('
'); Echo "[statement details ]"."
"; Print_r ($ downloadBill-> response); print_r ('
');}}

The preceding statement can only query data for one day at a time.

The returned Bill result is as follows:

Transaction time, public account ID, merchant number, sub-merchant number, device number, order number, merchant order number, user ID, transaction type, transaction status, payment Bank, currency type, total amount, enterprise red packet amount, refund ticket number, merchant refund ticket number, refund amount, enterprise red packet refund amount, refund type, refund status, product name, merchant data packet, handling fee, rate '2017-04-12 20:27:22, 'wx554f0b3e56067c9d, '2017, '0, 'wj4, '2017, '2017, 'omfx0jgjjspvvyoz3g _ BP8LclWO0, 'Native, 'Success, 'cmb _ CREDIT, 'cny, '71. 00, '0. 00, '0, '0, '0, '0, ',', 'best practices for public platform development, ', '0. 42600, '0. 60% '1970-04-12 18:08:38, 'wx554f0b3e56067c9d, '1970, '0, 'wj1, '000000', 'omfx0jhbq1xd0b6vm-kuizH9e9rs, 'Native, 'Success, 'comm _ DEBIT, 'cny, '92. 00, '0. 00, '0, '0, '0, '0, ',', 'best practices for public platform development, ', '0. 55200, '0. 60% '1970-04-12 19:12:06, 'wx554f0b3e56067c9d, '1970, '0, 'wj1, '1970, 'wx554f0b3e56067c9d1428837103, 'example, 'Native, 'Success, 'ceb _ CREDIT, 'cny, '69. 60, '0. 00, '0, '0, '0, '0, ',', 'best practices for public platform development, ', '0. 41760, '0. 60% '2017-04-12 13:03:25, 'wx554f0b3e56067c9d, '2017, '0, 'wj1, '2017, '2017, 'omfx0jthoxprccwebdjeyl1eizvg, 'Native, 'Success, 'cft, 'cny, '16. 80, '0. 00, '0, '0, '0, '0, ',', 'best practices for public platform development, ', '0. 10080, '0. 60% '2017-04-12 12:20:39, 'wx554f0b3e56067c9d, '2017, '0, 'wj2, '2017, 'wx554f0b3e56067c9d1428812423, '2017, 'Native, 'Success, 'ccb _ DEBIT, 'cny, '126. 60, '0. 00, '0, '0, '0, '0, ',', 'best practices for public platform development, ', '0. 75960, '0. 60% '2017-04-12 09:35:03, 'wx554f0b3e56067c9d, '2017, '0, 'WC 6, '2017, '2017, 'omfx0jmqtv9nbfol _-e83xYdXacM, 'Native, 'Success, 'cmbc _ DEBIT, 'cny, '0. 10, '0. 00, '0, '0, '0, '0, ',', 'best practices for public platform development, ', '0. 00060, '0. 60% '2017-04-12 09:23:20, 'wx554f0b3e56067c9d, '2017, '0, 'WC 6, '2017, '2017, 'omfx0jmqtv9nbfol _-e83xYdXacM, 'Native, 'Success, 'cmbc _ DEBIT, 'cny, '0. 10, '0. 00, '0, '0, '0, '0, ',', 'best practices for public platform development, ', '0. 00060, '0. 60% '2017-04-12 10:15:27, 'wx554f0b3e56067c9d, '2017, '0, 'wj5, '2017, '2017, 'omfx0jmqtv9nbfol _-e83xYdXacM, 'Native, 'Success, 'cft, 'cny, '0. 10, '0. 00, '0, '0, '0, '0, ',', 'best practices for public platform development, ', '0. 00060, '0. 60% '2017-04-12 10:10:09, 'wx554f0b3e56067c9d, '2017, '0, 'wj5, '2017, '2017, 'omfx0jmqtv9nbfol _-e83xYdXacM, 'Native, 'Success, 'cft, 'cny, '0. 10, '0. 00, '0, '0, '0, '0, ',', 'best practices for public platform development, ', '0. 00060, '0. 60% '2017-04-12 10:06:19, 'wx554f0b3e56067c9d, '2017, '0, 'WC 6, '2017, '2017, 'omfx0jmqtv9nbfol _-e83xYdXacM, 'Native, 'Success, 'cft, 'cny, '0. 10, '0. 00, '0, '0, '0, '0, ',', 'best practices for public platform development, ', '0. 00060, '0. 60% '1970-04-12 11:07:04, 'wx554f0b3e56067c9d, '1970, '0, 'wj1, '000000', 'omfx0jmqtv9nbfol _-e83xYdXacM, 'Native, 'Success, 'cft, 'cny, '0. 10, '0. 00, '0, '0, '0, '0, ',', 'best practices for public platform development, ', '0. 00060, '0. 60% '2017-04-12 11:27:07, 'wx554f0b3e56067c9d, '2017, '0, 'WC 6, '2017, '2017, 'omfx0jmqtv9nbfol _-e83xYdXacM, 'Native, 'Success, 'cft, 'cny, '0. 10, '0. 00, '0, '0, '0, '0, ',', 'best practices for public platform development, ', '0. 00060, '0. 60% '1970-04-12 16:24:48, 'wx554f0b3e56067c9d, '1970, '0, 'wj1, '1970, '2017, 'omfx0jk-zqqeyv7yZYEc4W1lWPVg, 'Native, 'cft, 'cny, '15. 80, '0. 00, '0, '0, '0, '0, ',', 'best practices for public platform development, ', '0. 09480, '0. 60% '1970-04-12 14:56:41, 'wx554f0b3e56067c9d, '1970, '0, 'wj1, '1970, 'hour, 'omfx0jnw _ NpAlwgSuJsyR8ocGSjI, 'Native, 'Success, 'ccb _ DEBIT, 'cny, '42. 00, '0. 00, '0, '0, '0, '0, ',', 'best practices for public platform development, ', '0. 25200, '0. 60% '2017-04-12 13:00:00, 'wx554f0b3e56067c9d, '2017, '0, 'wj1, '2017, 'wx554f0b3e56067c9d1428814787, '2017, 'Native, 'Success, 'pab _ CREDIT, 'cny, '16. 80, '0. 00, '0, '0, '0, '0, ',', 'best practices for public platform development, ', '0. 10080, '0. 60% '2017-04-12 16:13:48, 'wx554f0b3e56067c9d, '2017, '0, 'wj4, '2017, 'wx554f0b3e56067c9d1428826408, '2017, 'Native, 'Success, 'ABC _ DEBIT, 'cny, '120. 00, '0. 00, '0, '0, '0, '0, ',', 'best practices for public platform development, ', '0. 72000, '0. 60% '2017-04-12 09:49:04, 'wx554f0b3e56067c9d, '2017, '0, 'wj1, '2017, 'wx554f0b3e56067c9d1428803335, '2017-w, 'Native, 'Success, 'cft, 'cny, '0. 10, '0. 00, '0, '0, '0, '0, ',', 'best practices for public platform development, ', '0. 00060, '0. 60% Total transaction count, total transaction amount, total refund amount, total enterprise red envelope refund amount, total service fee '17, '100. 40, '0. 00, '0. 00, '3. 42840

If there is no bill for the current day, the following XML is returned:

     
  FAIL
      
  No Bill Exist
  
 

II. bill warehouse receiving

The preceding Bill data is a string of only one day, which is not conducive to statistics and query. You also need to download it to the database.

1. create a table

The billing fields include

Transaction time, public account ID, merchant number, sub-merchant number, device number, order number, merchant order number, user ID, transaction type, transaction status, payment Bank, currency type, total amount, coupon or discount amount, refund ticket number, merchant refund ticket number, refund amount, voucher or discount refund amount, refund type, refund status, product name, merchant data packet, service fee, rate

Based on the preceding fields, create the following table:

CREATE TABLE IF NOT EXISTS `wx_bill` (  `id` int(10) NOT NULL AUTO_INCREMENT,  `tradetime` varchar(20) NOT NULL,  `ghid` varchar(20) NOT NULL,  `mchid` varchar(20) NOT NULL,  `submch` varchar(10) NOT NULL,  `deviceid` varchar(16) NOT NULL,  `wxorder` varchar(30) NOT NULL,  `bzorder` varchar(30) NOT NULL,  `openid` varchar(30) NOT NULL,  `tradetype` varchar(10) NOT NULL,  `tradestatus` varchar(10) NOT NULL,  `bank` varchar(16) NOT NULL,  `currency` varchar(20) NOT NULL,  `totalmoney` varchar(20) NOT NULL,  `redpacketmoney` varchar(20) NOT NULL,  `wxrefund` varchar(10) NOT NULL,  `bzrefund` varchar(10) NOT NULL,  `refundmoney` varchar(20) NOT NULL,  `redpacketrefund` varchar(20) NOT NULL,  `refundtype` varchar(10) NOT NULL,  `refundstatus` varchar(10) NOT NULL,  `productname` varchar(30) NOT NULL,  `bzdatapacket` varchar(10) NOT NULL,  `fee` varchar(10) NOT NULL,  `rate` varchar(10) NOT NULL,  PRIMARY KEY (`id`),  UNIQUE KEY `wxorder` (`wxorder`),  UNIQUE KEY `bzorder` (`bzorder`)) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=272 ;

2. warehouse receiving

Insert the Bill data into the database as follows:

Insert into 'wx _ bill '('id', 'tradetime', 'ghid', 'mchid', 'submgi', 'deviceid', 'wxorder', 'bzorder ', 'openid', 'tradetype ', 'tradestatus', 'bank', 'currency', 'totalmoney', 'redpacketmoney', 'wxrefund ', 'bzrefund', 'refundmoney ', 'redpacketrefund', 'refundtype', 'refundstatus', 'productname ', 'bzdatapacket', 'rating', 'rate') VALUES (32, '2016', 'wx554f0b3e56067c9d ', '000000', '0', 'wj1', '000000', 'wx554f0b3e56067c9d1428814787 ', 'weight', 'native', 'success', 'pab _ credentials ', 'cny ', '16. 80', '0. 00', '0', '0', '0', '0', ',', 'best practices for public platform development ',', '0. 10080 ', '0. 60% '), (31, '000000', 'wx554f0b3e56067c9d', '000000', '0', 'wj1', '000000', 'wx554f0b3e56067c9d1428821791 ', 'omfx0jnw _ NpAlwgSuJsyR8ocGSjI ', 'native', 'success ', 'ccb _ DEBIT', 'cny ', '42. 00', '0. 00', '0', '0', '0', '0', ',', 'best practices for public platform development ',', '0. 25200 ', '0. 60% '), (30, '000000', 'wx554f0b3e56067c9d', '000000', '0', 'wj1', '000000', 'wx554f0b3e56067c9d1428827074 ', 'omfx0jk-zqqeyv7yzyec4w1lwpvg', 'native ', 'success', 'cft ', 'cny', '15. 80', '0. 00', '0', '0', '0', '0', ',', 'best practices for public platform development ',', '0. 09480 ', '0. 60% ');

II. statistical analysis

With local data, you can perform various statistical analysis.

1. condition combination

The following is an interface for combined query of bills. The device to be queried, the Payment type used, and the specified time range.

For more information about the payment development statement, see PHP!

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.