|
@@ -139,6 +139,67 @@ func GetMechantInfo(mechantCode string) (ret MechantPayInfo) {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// 获取APP微信支付需要的数据
|
|
|
|
|
+func GetAppPayData(outTradeNo string, totalPrice int64, body, notifyUrl, remoteIp, payCode string) (ret map[string]string) {
|
|
|
|
|
+ appId := beego.AppConfig.String("WxFohowAppAppId") //获取App appId
|
|
|
|
|
+ mechantInfo := GetMechantInfo(payCode)
|
|
|
|
|
+ prepayId := getAppPayPrepayId(outTradeNo, totalPrice, body, notifyUrl, remoteIp, payCode, true)
|
|
|
|
|
+ u := uuid.NewV4().String()
|
|
|
|
|
+ us := strings.Split(u, "-")
|
|
|
|
|
+ nonce_str := strings.Join(us, "")
|
|
|
|
|
+ ret = map[string]string{
|
|
|
|
|
+ "appId": appId,
|
|
|
|
|
+ "timeStamp": fmt.Sprintf("%d", time.Now().Unix()),
|
|
|
|
|
+ "package": fmt.Sprintf("prepay_id=%s", prepayId),
|
|
|
|
|
+ "signType": "MD5",
|
|
|
|
|
+ "nonceStr": nonce_str}
|
|
|
|
|
+ ret["paySign"] = mch.Sign(ret, mechantInfo.ApiKey, nil)
|
|
|
|
|
+ return ret
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// 获取支付预授权码
|
|
|
|
|
+// [pay.go:76] [E] GetPrepayId err[return_code: "FAIL", return_msg: "不识别的参数wxappid"]
|
|
|
|
|
+// 2016/07/07 11:07:02 [pay_controller.go:303] [W] 生成微信支付订单号:DS20160707503D648C,传的参数:openid=o7lR2txmVPh1pSPjIvto2LO_XVYU,
|
|
|
|
|
+// 价格:9.90, 名称:希客购, 客户端IP=119.132.31.240;生成的参数:%!v(MISSING)
|
|
|
|
|
+func getAppPayPrepayId(outTradeNo string, totalPrice int64, body, notifyUrl, remoteIp, payCode string, limit bool) (prepayId string) {
|
|
|
|
|
+ appId := beego.AppConfig.String("WxFohowAppAppId") //获取App渠道appId
|
|
|
|
|
+ mechantInfo := GetMechantInfo(payCode) //商户号配置信息
|
|
|
|
|
+ mchProxy := getMchProxyInitClient(payCode)
|
|
|
|
|
+
|
|
|
|
|
+ outTradeNo = fmt.Sprintf("%s_%d", outTradeNo, time.Now().Unix())
|
|
|
|
|
+ u := uuid.NewV4().String()
|
|
|
|
|
+ us := strings.Split(u, "-")
|
|
|
|
|
+ nonce_str := strings.Join(us, "")
|
|
|
|
|
+ req := map[string]string{
|
|
|
|
|
+ "mch_id": mechantInfo.MchId,
|
|
|
|
|
+ "appid": appId,
|
|
|
|
|
+ "nonce_str": nonce_str, //fmt.Sprintf("%d", time.Now().Unix()),
|
|
|
|
|
+ "body": body,
|
|
|
|
|
+ "out_trade_no": outTradeNo,
|
|
|
|
|
+ "total_fee": fmt.Sprintf("%d", totalPrice), //分为单位
|
|
|
|
|
+ "spbill_create_ip": remoteIp,
|
|
|
|
|
+ "notify_url": notifyUrl,
|
|
|
|
|
+ // "product_id": outTradeNo,
|
|
|
|
|
+ "trade_type": "APP",
|
|
|
|
|
+ // "limit_pay": "no_credit",
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if limit {
|
|
|
|
|
+ req["limit_pay"] = "no_credit"
|
|
|
|
|
+ }
|
|
|
|
|
+ sign := mch.Sign(req, mechantInfo.ApiKey, nil)
|
|
|
|
|
+ req["sign"] = sign
|
|
|
|
|
+ //beego.BeeLogger.Warn("%v", req)
|
|
|
|
|
+ ret, err := pay.UnifiedOrder(mchProxy, req)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ beego.BeeLogger.Error("GetPrepayId err[%s]", err)
|
|
|
|
|
+ //fmt.Println(err)
|
|
|
|
|
+ return ""
|
|
|
|
|
+ }
|
|
|
|
|
+ return ret["prepay_id"]
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// 获取jsSDK微信支付需要的数据
|
|
// 获取jsSDK微信支付需要的数据
|
|
|
func GetPayData(openid, outTradeNo string, totalPrice int64, body, notifyUrl, remoteIp, payCode string) (ret map[string]string) {
|
|
func GetPayData(openid, outTradeNo string, totalPrice int64, body, notifyUrl, remoteIp, payCode string) (ret map[string]string) {
|
|
|
appId := beego.AppConfig.String("WxFohowXcxAppId") //获取小程序渠道appId
|
|
appId := beego.AppConfig.String("WxFohowXcxAppId") //获取小程序渠道appId
|