abiao лет назад: 4
Родитель
Сommit
0f23396a02
2 измененных файлов с 72 добавлено и 0 удалено
  1. 11 0
      go/gopath/src/fohow.com/conf/app.conf
  2. 61 0
      go/gopath/src/fohow.com/libs/wx_mp/pay.go

+ 11 - 0
go/gopath/src/fohow.com/conf/app.conf

@@ -38,8 +38,14 @@ AliOssAccessSecret = "3QFdigF8Ngm5Z1X1U3WkTHYoAHyajh"
 AliOssEndPoint = "oss-cn-shenzhen.aliyuncs.com"
 AliOssEndPoint = "oss-cn-shenzhen.aliyuncs.com"
 AliCDNImgHost = "https://tcfohow.hiwavo.com"
 AliCDNImgHost = "https://tcfohow.hiwavo.com"
 
 
+#------------------------------------------------------------小程序appid
 WxFohowXcxAppId = "wx84f6c33a9fa3977d"
 WxFohowXcxAppId = "wx84f6c33a9fa3977d"
 WxFohowXcxAppSecret = "da2882779e983e2acfb573d01cb1fb7d"
 WxFohowXcxAppSecret = "da2882779e983e2acfb573d01cb1fb7d"
+
+#------------------------------------------------------------App appid
+WxFohowAppAppId = "wx84f6c33a9fa3977d"
+WxFohowAppAppSecret = "da2882779e983e2acfb573d01cb1fb7d"
+
 #------------------------------------------------------------
 #------------------------------------------------------------
 JsSDKConfigTicketAppId = "wxbddd1caf692557c4"
 JsSDKConfigTicketAppId = "wxbddd1caf692557c4"
 JsSDKConfigTicketAppSecret = "be6cb03f9a8c13a557728616a9e6039c"
 JsSDKConfigTicketAppSecret = "be6cb03f9a8c13a557728616a9e6039c"
@@ -160,6 +166,11 @@ AliCDNImgHost = "https://cfohow.hiwavo.com"
 
 
 WxFohowXcxAppId = "wx84f6c33a9fa3977d"
 WxFohowXcxAppId = "wx84f6c33a9fa3977d"
 WxFohowXcxAppSecret = "da2882779e983e2acfb573d01cb1fb7d"
 WxFohowXcxAppSecret = "da2882779e983e2acfb573d01cb1fb7d"
+
+#------------------------------------------------------------App appid
+WxFohowAppAppId = "wx84f6c33a9fa3977d"
+WxFohowAppAppSecret = "da2882779e983e2acfb573d01cb1fb7d"
+
 #------------------------------------------------------------
 #------------------------------------------------------------
 JsSDKConfigTicketAppId = "wx2479f58240be58aa"
 JsSDKConfigTicketAppId = "wx2479f58240be58aa"
 JsSDKConfigTicketAppSecret = "d9243f828f3c9dac198a539981a578b8"
 JsSDKConfigTicketAppSecret = "d9243f828f3c9dac198a539981a578b8"

+ 61 - 0
go/gopath/src/fohow.com/libs/wx_mp/pay.go

@@ -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