본 글에서는 위챗 결제 명세서 개발 및 구현 과정을 소개합니다.
현재 WeChat 결제는 v2 버전과 v3 버전으로 구분됩니다. 2014년 9월 10일 이전에 신청하신 분은 v2 버전, 그 이후에 신청하신 분은 v3 버전입니다. WeChat Pay V3 버전에는 paySignKey 매개변수가 없습니다. v2에 대한 관련 소개는 Fangbei Studio의 다른 기사를 참조하세요. 이 기사에서는 WeChat Pay v3를 소개합니다.
WeChat Pay v3는 명세서 데이터 인터페이스를 제공하며, 사용되는 인터페이스는
https:// api.mch .weixin.qq.com/pay/downloadbill
요청된 매개변수는 다음과 같습니다
|
변수 이름 | 필수 | 유형 |
값 예시 th> |
설명 |
공개 계정 ID |
appid | 예 | 문자열(32) | wx888888888888888 td>
bill_date |
예 |
문자열(8) |
20140603 | 명세서 다운로드 날짜, 형식: 20140603 |
사업자 번호 |
mch_id |
다음과 같습니다 |
문자열(32) | 1900000109 |
WeChat 결제에서 할당된 판매자 번호 |
기기 번호 |
device_info td>
|
임의 문자열 | nonce_str | 예 | 문자열(32) | 5K8264ILTKCH16CQ2502SI8ZNMTM67VS | 32자 이하의 임의 문자열입니다. 권장 난수 생성 알고리즘 | 서명 | sign |
은 |
문자열(32) |
C380BEC2BFD727A4B6845133519F3AD6 |
서명, 서명 생성 알고리즘 참조 |
청구서 유형 | bill_type | 아니요 | 문자열 (8) | ALL | ALL, 당일 주문 정보 모두 반환 , 기본값 SUCCESS, 당일 결제 완료된 반품 주문 REFUND, 당일 환불된 반품 주문 REVOKED, 취소된 주문 | / tr>
---|
include_once("../WxPayPubHelper/WxPayPubHelper.php"); //对账单日期 if (!isset($_POST["bill_date"])){ $bill_date = "20150401"; } else{ $bill_date = $_POST["bill_date"]; //使用对账单接口 $downloadBill = new DownloadBill_pub(); //设置对账单接口参数 //设置必填参数 //appid已填,商户无需重复填写 //mch_id已填,商户无需重复填写 //noncestr已填,商户无需重复填写 //sign已填,商户无需重复填写 $downloadBill->setParameter("bill_date","$bill_date");//对账单日期 $downloadBill->setParameter("bill_type","ALL");//账单类型 //非必填参数,商户可根据实际情况选填 //$downloadBill->setParameter("device_info","XXXX");//设备号 //$downloadBill->setParameter("device_info","方倍工作室1");//设备号 //对账单接口结果 $downloadBillResult = $downloadBill->getResult(); echo $downloadBillResult['return_code']; if ($downloadBillResult['return_code'] == "FAIL") { echo "通信出错:".$downloadBillResult['return_msg']; }else{ print_r('<pre class="brush:php;toolbar:false">'); echo "【对账单详情】"."</br>"; print_r($downloadBill->response); print_r('
交易时间,公众账号ID,商户号,子商户号,设备号,微信订单号,商户订单号,用户标识,交易类型,交易状态,付款银行,货币种类,总金额,企业红包金额,微信退款单号,商户退款单号,退款金额,企业红包退款金额,退款类型,退款状态,商品名称,商户数据包,手续费,费率 `2015-04-12 20:27:22,`wx554f0b3e56067c9d,`10024142,`0,`WJ4,`1000690206201504120059461630,`wx554f0b3e56067c9d1428841627,`oMfX0jgJjSPVvYOz3p_BP8LclWO0,`NATIVE,`SUCCESS,`CMB_CREDIT,`CNY,`71.00,`0.00,`0,`0,`0,`0,`,`,`微信公众平台开发最佳实践,`,`0.42600,`0.60% `2015-04-12 18:08:38,`wx554f0b3e56067c9d,`10024142,`0,`WJ1,`1001370206201504120059259734,`wx554f0b3e56067c9d1428833308,`oMfX0jhbQ1xd0B6Vm-kuizH9e9rs,`NATIVE,`SUCCESS,`COMM_DEBIT,`CNY,`92.00,`0.00,`0,`0,`0,`0,`,`,`微信公众平台开发最佳实践,`,`0.55200,`0.60% `2015-04-12 19:12:06,`wx554f0b3e56067c9d,`10024142,`0,`WJ1,`1001520206201504120059346120,`wx554f0b3e56067c9d1428837103,`oMfX0jj6h2ls1TsZEORs8WXRtSrE,`NATIVE,`SUCCESS,`CEB_CREDIT,`CNY,`69.60,`0.00,`0,`0,`0,`0,`,`,`微信公众平台开发最佳实践,`,`0.41760,`0.60% `2015-04-12 13:03:25,`wx554f0b3e56067c9d,`10024142,`0,`WJ1,`1002120206201504120058869224,`wx554f0b3e56067c9d1428814993,`oMfX0jtHOXPrCCWebdJEYl1eIzVg,`NATIVE,`SUCCESS,`CFT,`CNY,`16.80,`0.00,`0,`0,`0,`0,`,`,`微信公众平台开发最佳实践,`,`0.10080,`0.60% `2015-04-12 12:20:39,`wx554f0b3e56067c9d,`10024142,`0,`WJ2,`1002560206201504120058795541,`wx554f0b3e56067c9d1428812423,`oMfX0jhBckNfxRDHp2lUiFxXlCYE,`NATIVE,`SUCCESS,`CCB_DEBIT,`CNY,`126.60,`0.00,`0,`0,`0,`0,`,`,`微信公众平台开发最佳实践,`,`0.75960,`0.60% `2015-04-12 09:35:03,`wx554f0b3e56067c9d,`10024142,`0,`WJ6,`1003310206201504120058568869,`wx554f0b3e56067c9d1428802486,`oMfX0jmQtv9nBfol_-e83xYdXacM,`NATIVE,`SUCCESS,`CMBC_DEBIT,`CNY,`0.10,`0.00,`0,`0,`0,`0,`,`,`微信公众平台开发最佳实践,`,`0.00060,`0.60% `2015-04-12 09:23:20,`wx554f0b3e56067c9d,`10024142,`0,`WJ6,`1003310206201504120058569203,`wx554f0b3e56067c9d1428801789,`oMfX0jmQtv9nBfol_-e83xYdXacM,`NATIVE,`SUCCESS,`CMBC_DEBIT,`CNY,`0.10,`0.00,`0,`0,`0,`0,`,`,`微信公众平台开发最佳实践,`,`0.00060,`0.60% `2015-04-12 10:15:27,`wx554f0b3e56067c9d,`10024142,`0,`WJ5,`1003310206201504120058606779,`wx554f0b3e56067c9d1428804915,`oMfX0jmQtv9nBfol_-e83xYdXacM,`NATIVE,`SUCCESS,`CFT,`CNY,`0.10,`0.00,`0,`0,`0,`0,`,`,`微信公众平台开发最佳实践,`,`0.00060,`0.60% `2015-04-12 10:10:09,`wx554f0b3e56067c9d,`10024142,`0,`WJ5,`1003310206201504120058610924,`wx554f0b3e56067c9d1428804597,`oMfX0jmQtv9nBfol_-e83xYdXacM,`NATIVE,`SUCCESS,`CFT,`CNY,`0.10,`0.00,`0,`0,`0,`0,`,`,`微信公众平台开发最佳实践,`,`0.00060,`0.60% `2015-04-12 10:06:19,`wx554f0b3e56067c9d,`10024142,`0,`WJ6,`1003310206201504120058617007,`wx554f0b3e56067c9d1428804368,`oMfX0jmQtv9nBfol_-e83xYdXacM,`NATIVE,`SUCCESS,`CFT,`CNY,`0.10,`0.00,`0,`0,`0,`0,`,`,`微信公众平台开发最佳实践,`,`0.00060,`0.60% `2015-04-12 11:07:04,`wx554f0b3e56067c9d,`10024142,`0,`WJ1,`1003310206201504120058692567,`wx554f0b3e56067c9d1428808013,`oMfX0jmQtv9nBfol_-e83xYdXacM,`NATIVE,`SUCCESS,`CFT,`CNY,`0.10,`0.00,`0,`0,`0,`0,`,`,`微信公众平台开发最佳实践,`,`0.00060,`0.60% `2015-04-12 11:27:07,`wx554f0b3e56067c9d,`10024142,`0,`WJ6,`1003310206201504120058735881,`wx554f0b3e56067c9d1428809215,`oMfX0jmQtv9nBfol_-e83xYdXacM,`NATIVE,`SUCCESS,`CFT,`CNY,`0.10,`0.00,`0,`0,`0,`0,`,`,`微信公众平台开发最佳实践,`,`0.00060,`0.60% `2015-04-12 16:24:48,`wx554f0b3e56067c9d,`10024142,`0,`WJ1,`1003310206201504120059131508,`wx554f0b3e56067c9d1428827074,`oMfX0jk-zqqeyv7yZYEc4W1lWPVg,`NATIVE,`SUCCESS,`CFT,`CNY,`15.80,`0.00,`0,`0,`0,`0,`,`,`微信公众平台开发最佳实践,`,`0.09480,`0.60% `2015-04-12 14:56:41,`wx554f0b3e56067c9d,`10024142,`0,`WJ1,`1005430206201504120058999894,`wx554f0b3e56067c9d1428821791,`oMfX0jnw_NpAlwgSuJsyR8ocGSjI,`NATIVE,`SUCCESS,`CCB_DEBIT,`CNY,`42.00,`0.00,`0,`0,`0,`0,`,`,`微信公众平台开发最佳实践,`,`0.25200,`0.60% `2015-04-12 13:00:00,`wx554f0b3e56067c9d,`10024142,`0,`WJ1,`1006120206201504120058836372,`wx554f0b3e56067c9d1428814787,`oMfX0jnVvUaoR84XV8cP4ugcd9dk,`NATIVE,`SUCCESS,`PAB_CREDIT,`CNY,`16.80,`0.00,`0,`0,`0,`0,`,`,`微信公众平台开发最佳实践,`,`0.10080,`0.60% `2015-04-12 16:13:48,`wx554f0b3e56067c9d,`10024142,`0,`WJ4,`1007560206201504120059119673,`wx554f0b3e56067c9d1428826408,`oMfX0jlf4aVHBY1nel1XuNvb2m1A,`NATIVE,`SUCCESS,`ABC_DEBIT,`CNY,`120.00,`0.00,`0,`0,`0,`0,`,`,`微信公众平台开发最佳实践,`,`0.72000,`0.60% `2015-04-12 09:49:04,`wx554f0b3e56067c9d,`10024142,`0,`WJ1,`1009550206201504120058567546,`wx554f0b3e56067c9d1428803335,`oMfX0juZ58OdofLgirvkqK0FPq-w,`NATIVE,`SUCCESS,`CFT,`CNY,`0.10,`0.00,`0,`0,`0,`0,`,`,`微信公众平台开发最佳实践,`,`0.00060,`0.60% 总交易单数,总交易额,总退款金额,总企业红包退款金额,手续费总金额 `17,`571.40,`0.00,`0.00,`3.42840
<xml> <return_code><![CDATA[FAIL]]></return_code> <return_msg><![CDATA[No Bill Exist]]></return_msg> </xml>
交易时间,公众账号ID,商户号,子商户号,设备号,微信订单号,商户订单号,用户标识,交易类型,交易状态,付款银行,货币种类,总金额,代金券或立减优惠金额,微信退款单号,商户退款单号,退款金额, 代金券或立减优惠退款金额,退款类型,退款状态,商品名称,商户数据包,手续费,费率
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 ;
INSERT INTO `wx_bill` (`id`, `tradetime`, `ghid`, `mchid`, `submch`, `deviceid`, `wxorder`, `bzorder`, `openid`, `tradetype`, `tradestatus`, `bank`, `currency`, `totalmoney`, `redpacketmoney`, `wxrefund`, `bzrefund`, `refundmoney`, `redpacketrefund`, `refundtype`, `refundstatus`, `productname`, `bzdatapacket`, `fee`, `rate`) VALUES(32, '1428843600', 'wx554f0b3e56067c9d', '10024142', '0', 'WJ1', '1006120206201504120058836372', 'wx554f0b3e56067c9d1428814787', 'oMfX0jnVvUaoR84XV8cP4ugcd9dk', 'NATIVE', 'SUCCESS', 'PAB_CREDIT', 'CNY', '16.80', '0.00', '0', '0', '0', '0', '', '', '微信公众平台开发最佳实践', '', '0.10080', '0.60%'), (31, '1428850601', 'wx554f0b3e56067c9d', '10024142', '0', 'WJ1', '1005430206201504120058999894', 'wx554f0b3e56067c9d1428821791', 'oMfX0jnw_NpAlwgSuJsyR8ocGSjI', 'NATIVE', 'SUCCESS', 'CCB_DEBIT', 'CNY', '42.00', '0.00', '0', '0', '0', '0', '', '', '微信公众平台开发最佳实践', '', '0.25200', '0.60%'), (30, '1428855888', 'wx554f0b3e56067c9d', '10024142', '0', 'WJ1', '1003310206201504120059131508', 'wx554f0b3e56067c9d1428827074', 'oMfX0jk-zqqeyv7yZYEc4W1lWPVg', 'NATIVE', 'SUCCESS', 'CFT', 'CNY', '15.80', '0.00', '0', '0', '0', '0', '', '', '微信公众平台开发最佳实践', '', '0.09480', '0.60%');