package pay import ( "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/md" zhios_pay_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/utils" "crypto/tls" "io/ioutil" "net/http" "net/url" "strings" ) func UniPayByJoin(payParams *md.JoinPayReq, paySecretKey string, isPrd bool) (*md.JoinPayResponse, error) { payParams.P0Version = "2.1" payParams.P4Cur = "1" //可注释行: //payParams.P1MerchantNo = md.PayTestAccount //payParams.P2OrderNo = "95271" //payParams.P3Amount = "0.1" //payParams.P5ProductName = "测试商品" //payParams.P9NotifyUrl = "AB|https://www.baidu.com" //--交易类型 //payParams.Q1FrpCode = md.Q1FrpCodeWEIXINPAYAPP //payParams.Q1FrpCode = md.Q1FrpCodeALIPAY //原始微信AppId //payParams.Q7AppId = "gh_5a236de9850a" //微信AppId //payParams.Q7AppId = "wx5bb10bb79cb5da1c" //商家报备编号(分微信和支付宝的);支付宝的: //payParams.QATradeMerchantNo = md.PayTestAliAccount //商家报备编号(分微信和支付宝的);微信的: //payParams.QATradeMerchantNo = md.PayTestWeChatAccount //不可注释行: postData := url.Values{} creatHmac(payParams, paySecretKey, &postData) zhios_pay_utils.FilePutContents("UniPayByJoin", zhios_pay_utils.SerializeStr(map[string]interface{}{ "data": payParams, })) tr := &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, } client := &http.Client{Transport: tr} response, err := client.Post(md.JoinPayUrl, "application/x-www-form-urlencoded", strings.NewReader(postData.Encode())) if err != nil { return nil, err } defer response.Body.Close() body, err := ioutil.ReadAll(response.Body) resp := md.JoinPayResponse{} zhios_pay_utils.Unserialize(body, &resp) return &resp, err } func creatHmac(payParams *md.JoinPayReq, paySecretKey string, postData *url.Values) { hmac := "" if payParams.P0Version != "" { postData.Add("p0_Version", payParams.P0Version) hmac = hmac + payParams.P0Version } if payParams.P1MerchantNo != "" { postData.Add("p1_MerchantNo", payParams.P1MerchantNo) hmac = hmac + payParams.P1MerchantNo } if payParams.P2OrderNo != "" { postData.Add("p2_OrderNo", payParams.P2OrderNo) hmac = hmac + payParams.P2OrderNo } if payParams.P3Amount != "" { postData.Add("p3_Amount", payParams.P3Amount) hmac = hmac + payParams.P3Amount } if payParams.P4Cur != "" { postData.Add("p4_Cur", payParams.P4Cur) hmac = hmac + payParams.P4Cur } if payParams.P5ProductName != "" { postData.Add("p5_ProductName", payParams.P5ProductName) hmac = hmac + payParams.P5ProductName } if payParams.P6ProductDesc != "" { postData.Add("p6_ProductDesc", payParams.P6ProductDesc) hmac = hmac + payParams.P6ProductDesc } if payParams.P7Mp != "" { postData.Add("p7_Mp", payParams.P7Mp) hmac = hmac + payParams.P7Mp } if payParams.P9NotifyUrl != "" { postData.Add("p9_NotifyUrl", payParams.P9NotifyUrl) hmac = hmac + payParams.P9NotifyUrl } if payParams.Q1FrpCode != "" { postData.Add("q1_FrpCode", payParams.Q1FrpCode) hmac = hmac + payParams.Q1FrpCode } if payParams.Q2MerchantBankCode != "" { postData.Add("q2_MerchantBankCode", payParams.Q2MerchantBankCode) hmac = hmac + payParams.Q2MerchantBankCode } if payParams.Q4IsShowPic != "" { postData.Add("q4_IsShowPic", payParams.Q4IsShowPic) hmac = hmac + payParams.Q4IsShowPic } if payParams.Q5OpenId != "" { postData.Add("q5_OpenId", payParams.Q5OpenId) hmac = hmac + payParams.Q5OpenId } if payParams.Q6AuthCode != "" { postData.Add("q6_AuthCode", payParams.Q6AuthCode) hmac = hmac + payParams.Q6AuthCode } if payParams.Q7AppId != "" { postData.Add("q7_AppId", payParams.Q7AppId) hmac = hmac + payParams.Q7AppId } if payParams.Q8TerminalNo != "" { postData.Add("q8_TerminalNo", payParams.Q8TerminalNo) hmac = hmac + payParams.Q8TerminalNo } if payParams.Q9TransactionModel != "" { postData.Add("q9_TransactionModel", payParams.Q9TransactionModel) hmac = hmac + payParams.Q9TransactionModel } if payParams.QATradeMerchantNo != "" { postData.Add("qa_TradeMerchantNo", payParams.QATradeMerchantNo) hmac = hmac + payParams.QATradeMerchantNo } if payParams.QBbuyerId != "" { postData.Add("qb_buyerId", payParams.QBbuyerId) hmac = hmac + payParams.QBbuyerId } if payParams.QJDJPlan != "" { postData.Add("qj_DJPlan", payParams.QJDJPlan) hmac = hmac + payParams.QJDJPlan } if payParams.QKDisablePayModel != "" { postData.Add("qk_DisablePayModel", payParams.QKDisablePayModel) hmac = hmac + payParams.QKDisablePayModel } if payParams.QLTerminalIp != "" { postData.Add("ql_TerminalIp", payParams.QLTerminalIp) hmac = hmac + payParams.QLTerminalIp } payParams.Hmac = zhios_pay_utils.Md5(hmac + paySecretKey) postData.Add("hmac", payParams.Hmac) }