使用的包:
github.com/iGoogle-ink/gopay
前端用的uniapp
文档地址:https://uniapp.dcloud.io/api/plugins/payment
//上面是根据订单ID获取订单的一些基础数据
....
client := wechat.NewClient("微信开放平台申请的移动应用APPid", "商户ID", "商户APIkey", true)
//设置国家
client.SetCountry(wechat.China)
//初始化参数Map
bm := make(gopay.BodyMap)
bm.Set("nonce_str", util.GetRandomString(32)).
Set("body", "商品名称").
Set("out_trade_no", "你自己系统的订单号").
Set("total_fee", 商品价格*100).
Set("spbill_create_ip","下单人的IP").
Set("notify_url", "回调地址").
Set("trade_type", wechat.TradeType_App).
Set("device_info", "APP").
Set("sign_type", wechat.SignType_MD5)
//请求支付下单,成功后得到结果
wxRsp, err := client.UnifiedOrder(bm)
if err != nil {
xlog.