diff --git a/go.mod b/go.mod index f2905e6..e64001a 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,6 @@ require ( github.com/gomodule/redigo v1.8.8 github.com/iGoogle-ink/gopay v1.5.36 github.com/pkg/errors v0.9.1 - github.com/syyongx/php2go v0.9.6 go.uber.org/zap v1.16.0 golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 gopkg.in/natefinch/lumberjack.v2 v2.0.0 diff --git a/md/join.go b/md/join.go new file mode 100644 index 0000000..d34f483 --- /dev/null +++ b/md/join.go @@ -0,0 +1,55 @@ +package md + +const ( + JoinPayUrl = "https://www.joinpay.com/trade/uniPayApi.action" + PayTestAccount = "888118100005250" + PayTestSecretKey = "a12ceace4cc5423eae32b4626adf56c9" + Q1FrpCodeALIPAY = "ALIPAY_H5" //支付宝固定 + Q1FrpCodeWEIXINPAYAPP = "WEIXIN_APP3" //微信固定(应该) + //Q1FrpCodeWEIXINPAYH5 = "WEIXIN_H5_PLUS" + //Q1FrpCodeWEIXINPAYGZH = "WEIXIN_GZH" + //Q1FrpCodeWEIXINPAYXCX = "WEIXIN_XCX" + PayTestAliAccount = "777146200391877" + PayTestWeChatAccount = "777196100391173" +) + +// +// JoinPayReq +// @Description: 汇聚支付-聚合支付-支付接口-请求参数信息体 +// @Url: https://www.joinpay.com/open-platform/pages/document.html?apiName=%E8%81%9A%E5%90%88%E6%94%AF%E4%BB%98&id=6 +// +type JoinPayReq struct { + P0Version string `json:"p0_Version" label:"版本号;目前版本号为:2.1;是"` + P1MerchantNo string `json:"p1_MerchantNo" label:"商户编号;商户在支付平台系统的唯一身份标识;是"` + P2OrderNo string `json:"p2_OrderNo" label:"商户订单号;商户系统提交的唯一订单号。仅支持由英文字母、阿拉伯数字、下划线(英文符号“_”)组成的订单号传输;是"` + P3Amount string `json:"p3_Amount" label:"订单金额;单位:元,精确到分,保留两位小数。例如:10.23。;是"` + P4Cur string `json:"p4_Cur" label:"交易币种;默认设置为1(代表人民币);是"` + P5ProductName string `json:"p5_ProductName" label:"商品名称;用于支付时显示在支付平台网关上的订单产品信息;是"` + P6ProductDesc string `json:"p6_ProductDesc" label:"商品描述;对商品信息进行描述;否"` + P7Mp string `json:"p7_Mp" label:"公用回传参数;如果商户请求时传递了该参数,则返回给商户时会原值传回;否"` + P9NotifyUrl string `json:"p9_NotifyUrl" label:"服务器异步通知地址;汇聚支付系统主动通知商户网站里指定的 http 地址。 +异步通知地址需按: +1.AB|notifyUrl 的规则上送才会返回用户标识和平台优惠金额; +2.云闪付 CD|notifyUrl 的规则上才会返回用户支付的卡类型;是"` + Q1FrpCode string `json:"q1_FrpCode" label:"交易类型;可见md模型里提供的;是"` + Q2MerchantBankCode string `json:"q2_MerchantBankCode" label:"银行商户编码;非必填;否"` + Q4IsShowPic string `json:"q4_IsShowPic" label:"是否展示图片;默认为空,不输出图片;填1表示输出图片,仅交易类型为主扫时可用(即当q1_FrpCode=ALIPAY_NATIVE、WEIXIN_NATIVE、JD_NATIVE、QQ_NATIVE、UNIONPAY_NATIVE、BAIDU_NATIVE、SUNING_NATIVE);否"` + Q5OpenId string `json:"q5_OpenId" label:"微信Openid; +公众号获取用户Openid,公众号支付商户及微信小程序商户必填(即当q1_FrpCode=WEIXIN_GZH、WEIXIN_XCX);否"` + Q6AuthCode string `json:"q6_AuthCode" label:" +付款码数字;付款码数字被扫支付必填(即当q1_FrpCode= ALIPAY_CARD、WEIXIN_CARD、JD_CARD、QQ_CARD、UNIONPAY_CARD;否"` + Q7AppId string `json:"q7_AppId" label:"APPID;微信公众号、微信小程序、微信App、微信app+支付必填(即当q1_FrpCode= WEIXIN_GZH、WEIXIN_XCX、WEIXIN_APP3、WEIXIN_H5_PLUS【对应报备小程序appid】);否"` + Q8TerminalNo string `json:"q8_TerminalNo" label:" +终端设备号; +通过终端信息采集接口获取,由汇聚生成。微信/支付宝被扫支付必填(即当q1_FrpCode= ALIPAY_CARD、WEIXIN_CARD);否"` + Q9TransactionModel string `json:"q9_TransactionModel" label:"支付宝H5模式;支付宝H5选填,默认为空 + +1.模式一:当 q9_TransactionModel = MODEL1或为空时,有应答参数返回,rc_Result中返回html,需进行重定向跳转;2.模式二:当 q9_TransactionModel = MODEL2时,直接跳转链接,不返回应答参数。;否"` + QATradeMerchantNo string `json:"qa_TradeMerchantNo" label:"报备商户号;请填写报备产品后返回的报备商户号;是"` + QBbuyerId string `json:"qb_buyerId" label:"买家的支付宝唯一用户号;支付宝服务窗支付必填(即当q1_FrpCode=ALIPAY_FWC )(买家的支付宝唯一用户号(2088开头16位纯数字));否"` + QJDJPlan string `json:"qj_DJPlan" label:"点金计划;该字段参数值为JSON串;否"` + QKDisablePayModel string `json:"qk_DisablePayModel" label:"禁用支付方式;目前仅支持使用微信和支付宝支付时可禁用某些方式,详细枚举值见附录;否"` + QLTerminalIp string `json:"ql_TerminalIp" label:"终端设备IP; +商户端终端设备 IP 地址。微信/支付宝被扫支付必填(即当q1_FrpCode= ALIPAY_CARD、WEIXIN_CARD);否"` + Hmac string `json:"hmac" label:"签名数据;参见签名机制;是"` +} diff --git a/pay/pay_by_join.go b/pay/pay_by_join.go new file mode 100644 index 0000000..052f066 --- /dev/null +++ b/pay/pay_by_join.go @@ -0,0 +1,134 @@ +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" + "io/ioutil" + "net/http" + "net/url" + "strings" +) + +func UniPayByJoin(payParams *md.JoinPayReq, isPrd bool) (map[string]interface{}, error) { + payParams.P0Version = "2.1" + //payParams.P1MerchantNo = md.PayTestAccount + payParams.P4Cur = "1" + //payParams.P2OrderNo = "9527" + //payParams.P3Amount = "10" + //payParams.P5ProductName = "测试商品" + //payParams.P9NotifyUrl = "AB|https://www.baidu.com" + //--交易类型//payParams.Q1FrpCode = md.Q1FrpCodeWEIXINPAYH5 + //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, &postData) + zhios_pay_utils.FilePutContents("UniPayByJoin", zhios_pay_utils.SerializeStr(map[string]interface{}{ + "data": payParams, + })) + response, err := http.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 := make(map[string]interface{}) + zhios_pay_utils.Unserialize(body, &resp) + return resp, err +} + +func creatHmac(payParams *md.JoinPayReq, 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 + md.PayTestSecretKey) + postData.Add("hmac", payParams.Hmac) +} diff --git a/test/join_pay_test.go b/test/join_pay_test.go new file mode 100644 index 0000000..12b7664 --- /dev/null +++ b/test/join_pay_test.go @@ -0,0 +1,11 @@ +package test + +import ( + "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/md" + "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/pay" + "testing" +) + +func TestUniPayByJoin(t *testing.T) { + pay.UniPayByJoin(&md.JoinPayReq{}, false) +} diff --git a/utils/md5.go b/utils/md5.go new file mode 100644 index 0000000..6db0583 --- /dev/null +++ b/utils/md5.go @@ -0,0 +1,12 @@ +package zhios_pay_utils + +import ( + "crypto/md5" + "encoding/hex" +) + +func Md5(str string) string { + h := md5.New() + h.Write([]byte(str)) + return hex.EncodeToString(h.Sum(nil)) +}