(): GetOrderByOrderNoDb error.")
return "", err
}
nonceStr := GetRandomString(32)
//请求UnifiedOrder的代码
var yourReq UnifyOrderReq
yourReq.Appid = WX_APP_ID //微信开放平台我们创建出来的app的app id
yourReq.Body = bookOrder.LineNum
yourReq.Mch_id = WX_MCH_ID
yourReq.Nonce_str = nonceStr
yourReq.Notify_url = WX_NOTIFY_URL
yourReq.Trade_type = "APP"
yourReq.Spbill_create_ip = WX_INVOKE_API_IP
yourReq.Total_fee = int(bookOrder.TotalPrice * 100) //单位是分
yourReq.Out_trade_no = orderNo
var m map[string]interface{}
m = make(map[string]interface{}, 0)
m["appid"] = yourReq.Appid
m["body"] = yourReq.Body
m["mch_id"] = yourReq.Mch_id
m["notify_url"] = yourReq.Notify_url
m["trade_type"] = yourReq.Trade_type
m["spbill_create_ip"] = yourReq.Spbill_create_ip
m["total_fee"] = yourReq.Total_fee
m["out_trade_no"] = yourReq.Out_trade_no
m["nonce_str"] = yourReq.Nonce_str
yourReq.Sign = o.wxpayCalcSign(m, WX_PAY_KEY) // 这个是计算wxpay签名的函数上面已贴出
bytes_req, err := xml.Marshal(yourReq)
if err != nil {
log4go.Error("wxUnifyChargeReq(): xml.Marshal error:%s", err)
return "", err
}
str_req := string(bytes_req)
//wxpay的unifiedorder接口需要http body中xmldoc的根节点是<xml></xml>这种,所以这里需要replace一下
str_req = strings.Replace(str_req, "XUnifyOrderReq", "xml", -1)
bytes_req = []byte(str_req)
log4go.Debug("wxUnifyChargeReq()...str_req:%s", str_req)
//发送unified order请求.
req, err := http.NewRequest("POST", WX_UNIFIEDORDER_API, bytes.NewReader(bytes_req))
if err != nil {
log4go.Error("wxUnifyChargeReq(): http.NewRequest error:%s", err)
return "", err
}
req.Header.Set("Accept", "application/xml")
//这里的http header的设置是必须设置的.
req.Header.Set("Content-Type", "application/xml;charset=utf-8")
&nbs