本文为您提供了Go语言版本的充值接口接口对接DEMO示例
//测试:go run ./test.go
package main
import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
"strings"
)
const strUrl = "https://api.ihuyi.com/f/giftcard?action=buy"
func main() {
v := url.Values{}
v.Set("username", "123456") //API ID
v.Set("mobile", "130*******") //手机号
v.Set("orderid", "DD20253995959") //商家订单ID
v.Set("productid", "k111-1") //产品ID
v.Set("buynum", "1") //购买数量-固定数量1
v.Set("timestamp", "20240321150546") //时间戳格式如:yyyyMMddHHmmss 允许 10分钟统一以东 8 时间
v.Set("sign", "81ed625f338277f1bd7f27b9339e302c") //签名
body := strings.NewReader(v.Encode()) //把form数据编码
client := &http.Client{}
req, _ := http.NewRequest("POST", strUrl, body)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err := client.Do(req) //发送
if err != nil {
fmt.Println(err)
}
defer resp.Body.Close() //一定要关闭resp.Body
res, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(res))
}
在线咨询
150,000家
企业客户
21年
行业经验
2V1
2对1客户支持