日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

微信sdk服务器支付文档,微信支付-普通下单开发者文档

發布時間:2025/5/22 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 微信sdk服务器支付文档,微信支付-普通下单开发者文档 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

3.2. API接入(含示例代碼)

本章節展示了如何使用微信支付服務端 SDK 快速接入小程序支付產品,完成與微信支付對接的部分。

注意:

文檔中的代碼示例是用來闡述 API 基本使用方法,代碼中的示例參數需替換成商戶自己賬號及請求參數才能跑通。

以下接入步驟僅提供參考,請商戶結合自身業務需求進行評估、修改。

3.2.1. 【服務端】小程序支付統一下單

步驟說明:用戶通過商戶小程序進入商戶網頁,當用戶選擇相關商品購買時,商戶系統先調用該接口在微信支付服務后臺生成預支付交易單。

示例代碼

public void CreateOrder() throws Exception{

//請求URL

HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/pay/partner/transactions/jsapi");

// 請求body參數

String reqdata = "{"

+ "\"time_expire\":\"2018-06-08T10:34:56+08:00\","

+ "\"amount\": {"

+ "\"total\":100,"

+ "\"currency\":\"CNY\""

+ "},"

+ "\"settle_info\": {"

+ "\"profit_sharing\":false"

+ "},"

+ "\"sp_mchid\":\"1230000109\","

+ "\"description\":\"Image形象店-深圳騰大-QQ公仔\","

+ "\"sub_appid\":\"wxd678efh567hg6999\","

+ "\"notify_url\":\"https://www.weixin.qq.com/wxpay/pay.php\","

+ "\"payer\": {"

+ "\"sp_openid\":\"oUpF8uMuAJO_M2pxb1Q9zNjWeS6o\","

+ "\"sub_openid\":\"oUpF8uMuAJO_M2pxb1Q9zNjWeS6o\""

+ "},"

+ "\"sp_appid\":\"wx8888888888888888\","

+ "\"out_trade_no\":\"1217752501201407033233368018\","

+ "\"goods_tag\":\"WXG\","

+ "\"sub_mchid\":\"1900000109\","

+ "\"attach\":\"自定義數據說明\","

+ "\"detail\": {"

+ "\"invoice_id\":\"wx123\","

+ "\"goods_detail\": ["

+ "{"

+ "\"goods_name\":\"iPhoneX 256G\","

+ "\"wechatpay_goods_id\":\"1001\","

+ "\"quantity\":1,"

+ "\"merchant_goods_id\":\"商品編碼\","

+ "\"unit_price\":828800"

+ "},"

+ "{"

+ "\"goods_name\":\"iPhoneX 256G\","

+ "\"wechatpay_goods_id\":\"1001\","

+ "\"quantity\":1,"

+ "\"merchant_goods_id\":\"商品編碼\","

+ "\"unit_price\":828800"

+ "}"

+ "],"

+ "\"cost_price\":608800"

+ "},"

+ "\"scene_info\": {"

+ "\"store_info\": {"

+ "\"address\":\"廣東省深圳市南山區科技中一道10000號\","

+ "\"area_code\":\"440305\","

+ "\"name\":\"騰訊大廈分店\","

+ "\"id\":\"0001\""

+ "},"

+ "\"device_id\":\"013467007045764\","

+ "\"payer_client_ip\":\"14.23.150.211\""

+ "}"

+ "}";

StringEntity entity = new StringEntity(reqdata);

entity.setContentType("application/json");

httpPost.setEntity(entity);

httpPost.setHeader("Accept", "application/json");

//完成簽名并執行請求

CloseableHttpResponse response = httpClient.execute(httpPost);

try {

int statusCode = response.getStatusLine().getStatusCode();

if (statusCode == 200) { //處理成功

System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));

} else if (statusCode == 204) { //處理成功,無返回Body

System.out.println("success");

} else {

System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));

throw new IOException("request failed");

}

} finally {

response.close();

}

}

try {

$resp = $client->request(

'POST',

'https://api.mch.weixin.qq.com/v3/pay/partner/transactions/jsapi', //請求URL

[

// JSON請求體

'json' => [

"time_expire" => "2018-06-08T10:34:56+08:00",

"amount" => [

"total" => 100,

"currency" => "CNY",

],

"settle_info" => [

"profit_sharing" => false,

],

"sp_mchid" => "1230000109",

"description" => "Image形象店-深圳騰大-QQ公仔",

"sub_appid" => "wxd678efh567hg6999",

"notify_url" => "https://www.weixin.qq.com/wxpay/pay.php",

"payer" => [

"sp_openid" => "oUpF8uMuAJO_M2pxb1Q9zNjWeS6o",

"sub_openid" => "oUpF8uMuAJO_M2pxb1Q9zNjWeS6o",

],

"sp_appid" => "wx8888888888888888",

"out_trade_no" => "1217752501201407033233368018",

"goods_tag" => "WXG",

"sub_mchid" => "1900000109",

"attach" => "自定義數據說明",

"detail" => [

"invoice_id" => "wx123",

"goods_detail" => [

[

"goods_name" => "iPhoneX 256G",

"wechatpay_goods_id" => "1001",

"quantity" => 1,

"merchant_goods_id" => "商品編碼",

"unit_price" => 828800,

],

[

"goods_name" => "iPhoneX 256G",

"wechatpay_goods_id" => "1001",

"quantity" => 1,

"merchant_goods_id" => "商品編碼",

"unit_price" => 828800,

],

],

"cost_price" => 608800,

],

"scene_info" => [

"store_info" => [

"address" => "廣東省深圳市南山區科技中一道10000號",

"area_code" => "440305",

"name" => "騰訊大廈分店",

"id" => "0001",

],

"device_id" => "013467007045764",

"payer_client_ip" => "14.23.150.211",

]

],

'headers' => [ 'Accept' => 'application/json' ]

]

);

$statusCode = $resp->getStatusCode();

if ($statusCode == 200) { //處理成功

echo "success,return body = " . $resp->getBody()->getContents()."\n";

} else if ($statusCode == 204) { //處理成功,無返回Body

echo "success";

}

} catch (RequestException $e) {

// 進行錯誤處理

echo $e->getMessage()."\n";

if ($e->hasResponse()) {

echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";

}

return;

}

func CreateOrder() {

// 初始化客戶端

ctx := context.TODO()

opts, err := SetUp()

if err != nil {

return

}

client, err := core.NewClient(ctx, opts...,)

if err != nil{

log.Printf("init client err:%s",err)

return

}

//設置請求地址

URL := "https://api.mch.weixin.qq.com/v3/pay/partner/transactions/jsapi"

//設置請求信息,此處也可以使用結構體來進行請求

mapInfo := map[string]interface{}{

"sp_mchid": "1900007XXX",

"sub_mchid": "1900008XXX",

"out_trade_no": "1217752501201407033233368318",

"sp_appid": "wxdace645e0bc2cXXX",

"sub_appid": "wxdace645e0bc2cXXX",

"description": "Image形象店-深圳騰大-QQ公仔",

"notify_url": "https://weixin.qq.com/",

"amount": map[string]interface{}{

"total": 1,

"currency": "CNY",

},

"payer": map[string]interface{}{

"sp_openid": "o4GgauInH_RCEdvrrNGrntXDuXXX",

},

}

// 發起請求

response, err := client.Post(ctx, URL, mapInfo)

if err != nil{

log.Printf("client post err:%s",err)

return

}

// 校驗回包內容是否有邏輯錯誤

err = core.CheckResponse(response)

if err != nil{

log.Printf("check response err:%s",err)

return

}

// 讀取回包信息

body, err := ioutil.ReadAll(response.Body)

if err != nil{

log.Printf("read response body err:%s",err)

return

}

fmt.Println(string(body))

}

重要參數說明:

? out_trade_no:商戶系統內部訂單號,只能是數字、大小寫字母_-*且在同一個商戶號下唯一

? description:商品描述

? notify_url:支付回調通知URL,該地址必須為直接可訪問的URL,不允許攜帶查詢串

? total:訂單總金額,單位為分

? openid:openid是微信用戶在appid下的唯一用戶標識(appid不同,則獲取到的openid就不同),可用于永久標記一個用戶。openid獲取方式請參考以下文檔

小程序獲取openid、

公眾號獲取openid、

APP獲取openid、

更多參數、響應詳情及錯誤碼請參見JSAPI下單接口文檔

3.2.2.【客戶端】小程序調起支付API

步驟說明:通過JSAPI下單成功獲取預支付交易會話標識(prepay_id)后,需要通過小程序調起支付API來調起微信支付收銀臺

注意:

此API需要將請求參數進行簽名(參與簽名的參數為:appId、timeStamp、nonceStr、package,參數區分大小寫)

appId必須為最后拉起收銀臺的小程序appid

示例代碼:

wx.requestPayment(

{

"timeStamp": "1414561699",

"nonceStr": "5K8264ILTKCH16CQ2502SI8ZNMTM67VS",

"package": "prepay_id=wx201410272009395522657a690389285100",

"signType": "RSA",

"paySign": "oR9d8PuhnIc+YZ8cBHFCwfgpaK9gd7vaRvkYD7rthRAZ\/X+QBhcCYL21N7cHCTUxbQ+EAt6Uy+lwSN22f5YZvI45MLko8Pfso0jm46v5hqcVwrk6uddkGuT+Cdvu4WBqDzaDjnNa5UK3GfE1Wfl2gHxIIY5lLdUgWFts17D4WuolLLkiFZV+JSHMvH7eaLdT9N5GBovBwu5yYKUR7skR8Fu+LozcSqQixnlEZUfyE55feLOQTUYzLmR9pNtPbPsu6WVhbNHMS3Ss2+AehHvz+n64GDmXxbX++IOBvm2olHu3PsOUGRwhudhVf7UcGcunXt8cqNjKNqZLhLw4jq\/xDg==",

"success":function(res){},

"fail":function(res){},

"complete":function(res){}

})

? package:統一下單接口返回的prepay_id參數值,提交格式如:prepay_id=***

? signType:該接口V3版本僅支持RSA

? paySign:簽名

paySign生成規則、響應詳情請參見小程序調起支付API接口文檔

3.2.3.【服務端】接收支付結果通知

步驟說明:當用戶完成支付,微信會把相關支付結果將通過異步回調的方式通知商戶,商戶需要接收處理,并按文檔規范返回應答

注意:

支付結果通知是以POST 方法訪問商戶設置的通知url,通知的數據以JSON 格式通過請求主體(BODY)傳輸。通知的數據包括了加密的支付結果詳情

加密不能保證通知請求來自微信。微信會對發送給商戶的通知進行簽名,并將簽名值放在通知的HTTP頭Wechatpay-Signature。商戶應當驗證簽名,以確認請求來自微信,而不是其他的第三方。簽名驗證的算法請參考微信支付API v3簽名方案

支付通知http應答碼為200或204才會當作正常接收,當回調處理異常時,應答的HTTP狀態碼應為500,或者4xx

商戶成功接收到回調通知后應返回成功的http應答碼為200或204

同樣的通知可能會多次發送給商戶系統。商戶系統必須能夠正確處理重復的通知。 推薦的做法是,當商戶系統收到通知進行處理時,先檢查對應業務數據的狀態,并判斷該通知是否已經處理。如果未處理,則再進行處理;如果已處理,則直接返回結果成功。在對業務數據進行狀態檢查和處理之前,要采用數據鎖進行并發控制,以避免函數重入造成的數據混亂

對后臺通知交互時,如果微信收到商戶的應答不符合規范或超時,微信認為通知失敗,微信會通過一定的策略定期重新發起通知,盡可能提高通知的成功率,但微信不保證通知最終能成功。(通知頻率為15s/15s/30s/3m/10m/20m/30m/30m/30m/60m/3h/3h/3h/6h/6h - 總計 24h4m)

更多參數、響應詳情及錯誤碼請參見 JSAPI / APP / H5 / Native / 小程序支付通知API接口文檔

3.2.4. 【服務端】查詢訂單

步驟說明:當商戶后臺、網絡、服務器等出現異常,商戶系統最終未接收到支付通知時商戶可通過查詢訂單接口核實訂單支付狀態

示例代碼(通過微信訂單號查詢):

public void QueryOrder() throws Exception {

//請求URL

HttpGet httpGet = new HttpGet("https://api.mch.weixin.qq.com/v3/pay/partner/transactions/id/1217752501201407033233368018?sp_mchid=1230000109&sub_mchid=1900000109");

httpGet.setHeader("Accept", "application/json");

//完成簽名并執行請求

CloseableHttpResponse response = httpClient.execute(httpGet);

try {

int statusCode = response.getStatusLine().getStatusCode();

if (statusCode == 200) { //處理成功

System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));

} else if (statusCode == 204) { //處理成功,無返回Body

System.out.println("success");

} else {

System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));

throw new IOException("request failed");

}

} finally {

response.close();

}

}

try {

$resp = $client->request(

'GET',

'https://api.mch.weixin.qq.com/v3/pay/partner/transactions/id/1217752501201407033233368018?sp_mchid=1230000109&sub_mchid=1900000109', //請求URL

[

'headers' => [ 'Accept' => 'application/json']

]

);

$statusCode = $resp->getStatusCode();

if ($statusCode == 200) { //處理成功

echo "success,return body = " . $resp->getBody()->getContents()."\n";

} else if ($statusCode == 204) { //處理成功,無返回Body

echo "success";

}

} catch (RequestException $e) {

// 進行錯誤處理

echo $e->getMessage()."\n";

if ($e->hasResponse()) {

echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";

}

return;

}

func QueryOrder() {

// 初始化客戶端

ctx := context.TODO()

opts, err := SetUp()

if err != nil {

return

}

client, err := core.NewClient(ctx, opts...,)

if err != nil{

log.Printf("init client err:%s",err)

return

}

//設置請求地址

URL := "https://api.mch.weixin.qq.com/v3/pay/partner/transactions/id/4200000985202103031441826014?sp_mchid=1900007XXX&sub_mchid=1900008XXX"

// 發起請求

response, err := client.Get(ctx, URL)

if err != nil{

log.Printf("client get err:%s",err)

return

}

// 校驗回包內容是否有邏輯錯誤

err = core.CheckResponse(response)

if err != nil{

log.Printf("check response err:%s",err)

return

}

// 讀取回包信息

body, err := ioutil.ReadAll(response.Body)

if err != nil{

log.Printf("read response body err:%s",err)

return

}

fmt.Println(string(body))

}

注意:

查詢訂單可通過微信支付訂單號或商戶訂單號兩種方式查詢,兩種查詢方式返回結果相同

更多參數、響應詳情及錯誤碼請參見 JSAPI / APP / H5 / Native / 小程序查詢訂單API接口文檔

3.2.5. 【服務端】關閉訂單

步驟說明:當商戶訂單支付失敗需要生成新單號重新發起支付,要對原訂單號調用關單,避免重復支付;系統下單后,用戶支付超時,系統退出不再受理,避免用戶繼續,請調用關單接口

示例代碼:

public void CloseOrder() throws Exception {

//請求URL

HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/pay/partner/transactions/out-trade-no/{out_trade_no}/close");

// 請求body參數

String reqdata = "{"

+ "\"sp_mchid\":\"1230000109\","

+ "\"sub_mchid\":\"1900000109\""

+ "}";

StringEntity entity = new StringEntity(reqdata);

entity.setContentType("application/json");

httpPost.setEntity(entity);

httpPost.setHeader("Accept", "application/json");

//完成簽名并執行請求

CloseableHttpResponse response = httpClient.execute(httpPost);

try {

int statusCode = response.getStatusLine().getStatusCode();

if (statusCode == 200) { //處理成功

System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));

} else if (statusCode == 204) { //處理成功,無返回Body

System.out.println("success");

} else {

System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));

throw new IOException("request failed");

}

} finally {

response.close();

}

}

try {

$resp = $client->request(

'POST',

'https://api.mch.weixin.qq.com/v3/pay/partner/transactions/out-trade-no/{out_trade_no}/close', //請求URL

[

// JSON請求體

'json' => [

"sp_mchid" => "1230000109",

"sub_mchid" => "1900000109",

],

'headers' => [ 'Accept' => 'application/json' ]

]

);

$statusCode = $resp->getStatusCode();

if ($statusCode == 200) { //處理成功

echo "success,return body = " . $resp->getBody()->getContents()."\n";

} else if ($statusCode == 204) { //處理成功,無返回Body

echo "success";

}

} catch (RequestException $e) {

// 進行錯誤處理

echo $e->getMessage()."\n";

if ($e->hasResponse()) {

echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";

}

return;

}

func CloseOrder() {

// 初始化客戶端

ctx := context.TODO()

opts, err := SetUp()

if err != nil {

return

}

client, err := core.NewClient(ctx, opts...,)

if err != nil{

log.Printf("init client err:%s",err)

return

}

//設置請求地址

URL := "https://api.mch.weixin.qq.com/v3/pay/partner/transactions/out-trade-no/1217752501201407033233368018/close"

//設置請求信息,此處也可以使用結構體來進行請求

mapInfo := map[string]interface{}{

"sp_mchid": "1900007XXX",

"sub_mchid": "1900008XXX",

}

// 發起請求

response, err := client.Post(ctx, URL, mapInfo)

if err != nil{

log.Printf("client post err:%s",err)

return

}

// 校驗回包內容是否有邏輯錯誤

err = core.CheckResponse(response)

if err != nil{

log.Printf("check response err:%s",err)

return

}

// 讀取回包信息

body, err := ioutil.ReadAll(response.Body)

if err != nil{

log.Printf("read response body err:%s",err)

return

}

fmt.Println(string(body))

}

注意:

關單沒有時間限制,建議在訂單生成后間隔幾分鐘(最短5分鐘)再調用關單接口,避免出現訂單狀態同步不及時導致關單失敗。

已支付成功的訂單不能關閉

更多參數、響應詳情及錯誤碼請參見 JSAPI / APP / H5 / Native / 小程序接口文檔

3.2.6. 【服務端】申請交易賬單

步驟說明:微信支付按天提供交易賬單文件,商戶可以通過該接口獲取賬單文件的下載地址

示例代碼:

public void TradeBill() throws Exception {

//請求URL

HttpGet httpGet = new HttpGet("https://api.mch.weixin.qq.com/v3/bill/tradebill?bill_date=2019-06-11&sub_mchid=1900000001&bill_type=ALL");

httpGet.setHeader("Accept", "application/json");

//完成簽名并執行請求

CloseableHttpResponse response = httpClient.execute(httpGet);

try {

int statusCode = response.getStatusLine().getStatusCode();

if (statusCode == 200) { //處理成功

System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));

} else if (statusCode == 204) { //處理成功,無返回Body

System.out.println("success");

} else {

System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));

throw new IOException("request failed");

}

} finally {

response.close();

}

}

try {

$resp = $client->request(

'GET',

'https://api.mch.weixin.qq.com/v3/bill/tradebill?bill_date=2019-06-11&sub_mchid=1900000001&bill_type=ALL', //請求URL

[

'headers' => [ 'Accept' => 'application/json']

]

);

$statusCode = $resp->getStatusCode();

if ($statusCode == 200) { //處理成功

echo "success,return body = " . $resp->getBody()->getContents()."\n";

} else if ($statusCode == 204) { //處理成功,無返回Body

echo "success";

}

} catch (RequestException $e) {

// 進行錯誤處理

echo $e->getMessage()."\n";

if ($e->hasResponse()) {

echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";

}

return;

}

func TradeBill() {

// 初始化客戶端

ctx := context.TODO()

opts, err := SetUp()

if err != nil {

return

}

client, err := core.NewClient(ctx, opts...,)

if err != nil{

log.Printf("init client err:%s",err)

return

}

//設置請求地址

URL := "https://api.mch.weixin.qq.com/v3/bill/tradebill?bill_date=2019-06-11&sub_mchid=1900000001&bill_type=ALL"

// 發起請求

response, err := client.Get(ctx, URL)

if err != nil{

log.Printf("client get err:%s",err)

return

}

// 校驗回包內容是否有邏輯錯誤

err = core.CheckResponse(response)

if err != nil{

log.Printf("check response err:%s",err)

return

}

// 讀取回包信息

body, err := ioutil.ReadAll(response.Body)

if err != nil{

log.Printf("read response body err:%s",err)

return

}

fmt.Println(string(body))

}

注意:

更多參數、響應詳情及錯誤碼請參見 JSAPI / APP / H5 / Native / 小程序接口文檔

3.2.7. 【服務端】下載賬單

步驟說明:通過申請交易賬單接口獲取到賬單下載地址(download_url)后,再通過該接口獲取到對應的賬單文件,文件內包含交易相關的金額、時間、營銷等信息,供商戶核對訂單、退款、銀行到賬等情況

示例代碼:

public void DownloadUrl(String download_url) throws Exception{

PrivateKey merchantPrivateKey = PemUtil.loadPrivateKey(new ByteArrayInputStream(privateKey.getBytes("utf-8")));

//初始化httpClient

//該接口無需進行簽名驗證、通過withValidator((response) -> true)實現

httpClient = WechatPayHttpClientBuilder.create().withMerchant(mchId, mchSerialNo, merchantPrivateKey).withValidator((response) -> true).build();

//請求URL

//賬單文件的下載地址的有效時間為30s

URIBuilder uriBuilder = new URIBuilder(download_url);

HttpGet httpGet = new HttpGet(uriBuilder.build());

httpGet.addHeader("Accept", "application/json");

//執行請求

CloseableHttpResponse response = httpClient.execute(httpGet);

try {

int statusCode = response.getStatusLine().getStatusCode();

if (statusCode == 200) {

System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));

} else if (statusCode == 204) {

System.out.println("success");

} else {

System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));

throw new IOException("request failed");

}

} finally {

response.close();

}

}

try {

$resp = $client->request(

'GET',

'https://api.mch.weixin.qq.com/v3/billdownload/file?token=xx', //請求URL

[

'headers' => [ 'Accept' => 'application/json']

]

);

$statusCode = $resp->getStatusCode();

if ($statusCode == 200) { //處理成功

echo "success,return body = " . $resp->getReasonPhrase()."\n";

} else if ($statusCode == 204) { //處理成功,無返回Body

echo "success";

}

} catch (RequestException $e) {

// 進行錯誤處理

echo $e->getMessage()."\n";

if ($e->hasResponse()) {

echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";

}

return;

}

func CreateOrder() {

// 初始化客戶端

ctx := context.TODO()

opts, err := SetUp()

if err != nil {

return

}

client, err := core.NewClient(ctx, opts...,)

if err != nil{

log.Printf("init client err:%s",err)

return

}

//設置請求地址

URL := "https://api.mch.weixin.qq.com/v3/billdownload/file?token=xxx" //申請賬單接口獲取到的download_url

// 發起請求

response, err := client.Get(ctx, URL)

if err != nil{

log.Printf("client get err:%s",err)

return

}

// 校驗回包內容是否有邏輯錯誤

err = core.CheckResponse(response)

if err != nil{

log.Printf("check response err:%s",err)

return

}

// 讀取回包信息

body, err := ioutil.ReadAll(response.Body)

if err != nil{

log.Printf("read response body err:%s",err)

return

}

fmt.Println(string(body))

}

注意:

? 賬單文件的下載地址的有效時間為30s

? 強烈建議商戶將實際賬單文件的哈希值和之前從接口獲取到的哈希值進行比對,以確認數據的完整性

更多參數、響應詳情及錯誤碼請參見 JSAPI / APP / H5 / Native / 小程序下載賬單API接口文檔

總結

以上是生活随笔為你收集整理的微信sdk服务器支付文档,微信支付-普通下单开发者文档的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。