|
@@ -0,0 +1,98 @@
|
|
|
|
|
+package wx_mp
|
|
|
|
|
+
|
|
|
|
|
+import (
|
|
|
|
|
+ "fmt"
|
|
|
|
|
+ "github.com/astaxie/beego"
|
|
|
|
|
+ "github.com/chanxuehong/wechat/mch/pay"
|
|
|
|
|
+ "github.com/uuid"
|
|
|
|
|
+ "strings"
|
|
|
|
|
+ "time"
|
|
|
|
|
+
|
|
|
|
|
+ // "github.com/astaxie/beego/context"
|
|
|
|
|
+ "github.com/chanxuehong/wechat/mch"
|
|
|
|
|
+ // "github.com/chanxuehong/wechat/mp/user"
|
|
|
|
|
+ // "go.xikego.com/apps/models/shop_model"
|
|
|
|
|
+ // "go.xikego.com/cache"
|
|
|
|
|
+)
|
|
|
|
|
+
|
|
|
|
|
+const (
|
|
|
|
|
+
|
|
|
|
|
+ //乐福收款公众号
|
|
|
|
|
+ lehuWxMchId = "1581904571"
|
|
|
|
|
+ lehuWxApiKey = "r1sbdza2mgs2zo3x2u6w8plgh91z0gqq"
|
|
|
|
|
+)
|
|
|
|
|
+
|
|
|
|
|
+var lehumchProxy = mch.NewProxy(appId, lehuWxMchId, lehuWxApiKey, nil)
|
|
|
|
|
+
|
|
|
|
|
+//小程序乐福商户
|
|
|
|
|
+var lehuTlsHttpCilent, _ = mch.NewTLSHttpClient(
|
|
|
|
|
+ beego.AppConfig.String("LehuMchCertFile"),
|
|
|
|
|
+ beego.AppConfig.String("LehuMchKeyFile"))
|
|
|
|
|
+var lehuMchTLSProxy = mch.NewProxy(appId, lehuWxMchId, lehuWxApiKey, lehuTlsHttpCilent)
|
|
|
|
|
+
|
|
|
|
|
+// 获取jsSDK微信支付需要的数据
|
|
|
|
|
+func GetLehuPayDataLimitPay(openid, outTradeNo string, totalPrice int64, body, notifyUrl, remoteIp string) (ret map[string]string) {
|
|
|
|
|
+ prepayId := getLehuPayPrepayIdLimitPay(openid, outTradeNo, totalPrice, body, notifyUrl, remoteIp)
|
|
|
|
|
+ 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, lehuWxApiKey, 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 getLehuPayPrepayIdLimitPay(openid, outTradeNo string, totalPrice int64, body, notifyUrl, remoteIp string) (prepayId string) {
|
|
|
|
|
+ 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": lehuWxMchId,
|
|
|
|
|
+ "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": "JSAPI",
|
|
|
|
|
+ "limit_pay": "no_credit",
|
|
|
|
|
+ //"用户在商户 appid 下的唯一标识,trade_type 为 JSAPI时,此参数必传,获取方式见表头说明。",
|
|
|
|
|
+ "openid": openid}
|
|
|
|
|
+ sign := mch.Sign(req, lehuWxApiKey, 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"]
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// 校验支付结果回调参数--乐福微信
|
|
|
|
|
+func LehuVerifyPayResult(payResult *PayResult) bool {
|
|
|
|
|
+ sign := payResult.Sign
|
|
|
|
|
+ params, err := XmlStructToMap(payResult)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ beego.BeeLogger.Error("transfer xmlstruct to map err=[%s]", err)
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+ // beego.BeeLogger.Warn("*****params: %v", params)
|
|
|
|
|
+ // beego.BeeLogger.Warn("*****sign: %s", sign)
|
|
|
|
|
+ mchSign := mch.Sign(params, lehuWxApiKey, nil)
|
|
|
|
|
+ // beego.BeeLogger.Warn("*****mch sign: %s", mchSign)
|
|
|
|
|
+ return sign == mchSign
|
|
|
|
|
+}
|