您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關(guān)微信支付開發(fā)之如何實(shí)現(xiàn)賬單的內(nèi)容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧。
一、對(duì)賬單數(shù)據(jù)接口
微信支付v3提供了對(duì)賬單的數(shù)據(jù)接口,其使用的接口為
https://api.mch.weixin.qq.com/pay/downloadbill
請(qǐng)求的參數(shù)如下
字段名 | 變量名 | 必填 | 類型 | 示例值 | 描述 |
---|---|---|---|---|---|
公眾賬號(hào)ID | appid | 是 | String(32) | wx8888888888888888 | 微信分配的公眾賬號(hào)ID |
商戶號(hào) | mch_id | 是 | String(32) | 1900000109 | 微信支付分配的商戶號(hào) |
設(shè)備號(hào) | device_info | 否 | String(32) | 013467007045764 | 微信支付分配的終端設(shè)備號(hào),填寫此字段,只下載該設(shè)備號(hào)的對(duì)賬單 |
隨機(jī)字符串 | nonce_str | 是 | String(32) | 5K8264ILTKCH16CQ2502SI8ZNMTM67VS | 隨機(jī)字符串,不長(zhǎng)于32位。推薦隨機(jī)數(shù)生成算法 |
簽名 | sign | 是 | String(32) | C380BEC2BFD727A4B6845133519F3AD6 | 簽名,詳見(jiàn)簽名生成算法 |
對(duì)賬單日期 | bill_date | 是 | String(8) | 20140603 | 下載對(duì)賬單的日期,格式:20140603 |
賬單類型 | bill_type | 否 | String(8) | ALL | ALL,返回當(dāng)日所有訂單信息,默認(rèn)值 SUCCESS,返回當(dāng)日成功支付的訂單 REFUND,返回當(dāng)日退款訂單 REVOKED,已撤銷的訂單 |
Demo中的實(shí)現(xiàn)代碼如下
include_once("../WxPayPubHelper/WxPayPubHelper.php"); //對(duì)賬單日期 if (!isset($_POST["bill_date"])){ $bill_date = "20150401"; } else{ $bill_date = $_POST["bill_date"]; //使用對(duì)賬單接口 $downloadBill = new DownloadBill_pub(); //設(shè)置對(duì)賬單接口參數(shù) //設(shè)置必填參數(shù) //appid已填,商戶無(wú)需重復(fù)填寫 //mch_id已填,商戶無(wú)需重復(fù)填寫 //noncestr已填,商戶無(wú)需重復(fù)填寫 //sign已填,商戶無(wú)需重復(fù)填寫 $downloadBill->setParameter("bill_date","$bill_date");//對(duì)賬單日期 $downloadBill->setParameter("bill_type","ALL");//賬單類型 //非必填參數(shù),商戶可根據(jù)實(shí)際情況選填 //$downloadBill->setParameter("device_info","XXXX");//設(shè)備號(hào) //$downloadBill->setParameter("device_info","方倍工作室1");//設(shè)備號(hào) //對(duì)賬單接口結(jié)果 $downloadBillResult = $downloadBill->getResult(); echo $downloadBillResult['return_code']; if ($downloadBillResult['return_code'] == "FAIL") { echo "通信出錯(cuò):".$downloadBillResult['return_msg']; }else{ print_r('<pre>'); echo "【對(duì)賬單詳情】"."</br>"; print_r($downloadBill->response); print_r('</pre>'); } }
上述對(duì)賬單一次只能查詢一天的數(shù)據(jù)。
其返回的賬單結(jié)果如下
交易時(shí)間,公眾賬號(hào)ID,商戶號(hào),子商戶號(hào),設(shè)備號(hào),微信訂單號(hào),商戶訂單號(hào),用戶標(biāo)識(shí),交易類型,交易狀態(tài),付款銀行,貨幣種類,總金額,企業(yè)紅包金額,微信退款單號(hào),商戶退款單號(hào),退款金額,企業(yè)紅包退款金額,退款類型,退款狀態(tài),商品名稱,商戶數(shù)據(jù)包,手續(xù)費(fèi),費(fèi)率 `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,`,`,`微信公眾平臺(tái)開發(fā)最佳實(shí)踐,`,`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,`,`,`微信公眾平臺(tái)開發(fā)最佳實(shí)踐,`,`0.55200,`0.60% `2015-04-12 19:12:06,`wx554f0b3e56067c9d,`10024142,`0,`WJ1,`1001520206201504120059346120,`wx554f0b3e56067c9d1428837103,`oMfX0jj6h3ls1TsZEORs8WXRtSrE,`NATIVE,`SUCCESS,`CEB_CREDIT,`CNY,`69.60,`0.00,`0,`0,`0,`0,`,`,`微信公眾平臺(tái)開發(fā)最佳實(shí)踐,`,`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,`,`,`微信公眾平臺(tái)開發(fā)最佳實(shí)踐,`,`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,`,`,`微信公眾平臺(tái)開發(fā)最佳實(shí)踐,`,`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,`,`,`微信公眾平臺(tái)開發(fā)最佳實(shí)踐,`,`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,`,`,`微信公眾平臺(tái)開發(fā)最佳實(shí)踐,`,`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,`,`,`微信公眾平臺(tái)開發(fā)最佳實(shí)踐,`,`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,`,`,`微信公眾平臺(tái)開發(fā)最佳實(shí)踐,`,`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,`,`,`微信公眾平臺(tái)開發(fā)最佳實(shí)踐,`,`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,`,`,`微信公眾平臺(tái)開發(fā)最佳實(shí)踐,`,`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,`,`,`微信公眾平臺(tái)開發(fā)最佳實(shí)踐,`,`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,`,`,`微信公眾平臺(tái)開發(fā)最佳實(shí)踐,`,`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,`,`,`微信公眾平臺(tái)開發(fā)最佳實(shí)踐,`,`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,`,`,`微信公眾平臺(tái)開發(fā)最佳實(shí)踐,`,`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,`,`,`微信公眾平臺(tái)開發(fā)最佳實(shí)踐,`,`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,`,`,`微信公眾平臺(tái)開發(fā)最佳實(shí)踐,`,`0.00060,`0.60% 總交易單數(shù),總交易額,總退款金額,總企業(yè)紅包退款金額,手續(xù)費(fèi)總金額 `17,`571.40,`0.00,`0.00,`3.42840
如果當(dāng)天沒(méi)有賬單,則返回XML如下
<xml> <return_code><![CDATA[FAIL]]></return_code> <return_msg><![CDATA[No Bill Exist]]></return_msg> </xml>
二、賬單入庫(kù)
上述的賬單數(shù)據(jù)是個(gè)字符串,且只是一天的數(shù)據(jù),不利于統(tǒng)計(jì)及查詢。還需要下載到數(shù)據(jù)庫(kù)中來(lái)。
1. 建表
賬單的字段有這些
交易時(shí)間,公眾賬號(hào)ID,商戶號(hào),子商戶號(hào),設(shè)備號(hào),微信訂單號(hào),商戶訂單號(hào),用戶標(biāo)識(shí),交易類型,交易狀態(tài),付款銀行,貨幣種類,總金額,代金券或立減優(yōu)惠金額,微信退款單號(hào),商戶退款單號(hào),退款金額, 代金券或立減優(yōu)惠退款金額,退款類型,退款狀態(tài),商品名稱,商戶數(shù)據(jù)包,手續(xù)費(fèi),費(fèi)率
根據(jù)上述字段,建表如下
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 ;
將微信賬單的數(shù)據(jù)插入到數(shù)據(jù)庫(kù)中,實(shí)現(xiàn)如下
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', '', '', '微信公眾平臺(tái)開發(fā)最佳實(shí)踐', '', '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', '', '', '微信公眾平臺(tái)開發(fā)最佳實(shí)踐', '', '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', '', '', '微信公眾平臺(tái)開發(fā)最佳實(shí)踐', '', '0.09480', '0.60%');
二、統(tǒng)計(jì)分析
有了本地?cái)?shù)據(jù),就可以進(jìn)行各種統(tǒng)計(jì)分析了。
下面是一種進(jìn)行組合查詢賬單的界面實(shí)現(xiàn)。需要查詢使用的設(shè)備,使用的支付類型,及指定的時(shí)間范圍。
其查詢的結(jié)果如下所示
感謝各位的閱讀!關(guān)于“微信支付開發(fā)之如何實(shí)現(xiàn)賬單”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。