main
ljl 5 months ago
parent ff3f281afb
commit 446a786cfe

@ -313,6 +313,22 @@ func GatewayPay(c *gin.Context) {
return return
} }
func UnionPay(c *gin.Context) {
c.Writer.Header().Set("content-type", "text/html")
token := c.DefaultQuery("token", "")
if token == "" {
c.Writer.WriteString("token empty")
return
}
body, err := service.PaymentService.UnionPay(token)
if err != nil {
c.Writer.WriteString(err.Error())
return
}
c.Writer.WriteString(body)
return
}
func BankCardUnbind(c *gin.Context) (result.Data, error) { func BankCardUnbind(c *gin.Context) (result.Data, error) {
err := service.UserService.BankCardUnbind(user(c)) err := service.UserService.BankCardUnbind(user(c))
if err != nil { if err != nil {

@ -18,6 +18,7 @@ func h5RouteInit(r *gin.Engine) {
h5Group.Match([]string{"POST", "OPTIONS"}, "/binding-pay-notify", h5.BindingPayNotify) h5Group.Match([]string{"POST", "OPTIONS"}, "/binding-pay-notify", h5.BindingPayNotify)
h5Group.Match([]string{"GET", "OPTIONS"}, "/test-gateway-pay", h5.GatewayPay) h5Group.Match([]string{"GET", "OPTIONS"}, "/test-gateway-pay", h5.GatewayPay)
h5Group.Match([]string{"GET", "OPTIONS"}, "/gateway-pay", h5.GatewayPay) h5Group.Match([]string{"GET", "OPTIONS"}, "/gateway-pay", h5.GatewayPay)
h5Group.Match([]string{"GET", "OPTIONS"}, "/union-pay", h5.UnionPay)
h5Group.Match([]string{"POST", "GET", "OPTIONS"}, "/gateway-pay-ret", h5.GatewayPayRet) h5Group.Match([]string{"POST", "GET", "OPTIONS"}, "/gateway-pay-ret", h5.GatewayPayRet)
authGroup := h5Group.Group("") authGroup := h5Group.Group("")

@ -53,6 +53,8 @@ func (s paymentService) Payment(userID int, paymentRequest request.PaymentReques
data, err = s.bindingPayment(paymentRequest, p) data, err = s.bindingPayment(paymentRequest, p)
} else if paymentRequest.PayType == "gateway" { } else if paymentRequest.PayType == "gateway" {
data, err = s.getGatewayPayUrl(p) data, err = s.getGatewayPayUrl(p)
} else if paymentRequest.PayType == "union" {
data, err = s.getUnionPayUrl(p)
} else { } else {
err = errors.NewBusinessError("payType参数错误") err = errors.NewBusinessError("payType参数错误")
} }
@ -439,3 +441,35 @@ func (s paymentService) getGatewayPayUrl(pm *model.Payment) (result.Data, error)
data := result.Data{"url": "http://api.wrtcjt.com/h5/gateway-pay?token=" + token, "orderId": ""} data := result.Data{"url": "http://api.wrtcjt.com/h5/gateway-pay?token=" + token, "orderId": ""}
return data, nil return data, nil
} }
func (s paymentService) getUnionPayUrl(pm *model.Payment) (result.Data, error) {
token := utils.Md5(pm.PaymentNo + strconv.Itoa(pm.UserID) + "_union")
pm.Token = token
err := global.DB.Save(pm).Error
if err != nil {
return nil, err
}
data := result.Data{"url": "http://api.wrtcjt.com/h5/union-pay?token=" + token, "orderId": ""}
return data, nil
}
func (s paymentService) UnionPay(token string) (string, error) {
pm := &model.Payment{}
err := global.DB.Where("token", token).Where("status", 0).First(&pm).Error
if err != nil {
return "", err
}
p := param.UnionOrderParam{}
p.ReqSn = pm.PaymentNo
p.TrxAmt = strconv.FormatFloat(pm.Amount*100, 'f', 0, 64)
p.LimitPay = "no_credit"
p.RetUrl = "http://api.wrtcjt.com/h5/gateway-pay-ret"
p.NotifyUrl = "http://api.wrtcjt.com/h5/binding-pay-notify"
p.Body = "充值"
p.Charset = "UTF-8"
p.PayType = "VSP511"
str := tlpay.TLPay.UnionPay(p)
return str, nil
}

@ -237,10 +237,21 @@ func (api *tlPay) GatewayPay(p param.GatewayPayParam) string {
data = api.SetCommonParams(data, false) data = api.SetCommonParams(data, false)
sign, _ := api.sign(data) sign, _ := api.sign(data)
data.Set("sign", sign) data.Set("sign", sign)
return api.BuildForm(data) payConfig := global.Config.TlPay
formUrl := payConfig.BaseUrl + "/apiweb/gateway/pay"
return api.BuildForm(formUrl, data)
}
func (api *tlPay) UnionPay(p param.UnionOrderParam) string {
data, _ := utils.StructToURLValues(p)
data = api.SetCommonParams(data, false)
sign, _ := api.sign(data)
data.Set("sign", sign)
formUrl := "https://syb.allinpay.com/apiweb/h5unionpay/unionorder"
return api.BuildForm(formUrl, data)
} }
func (api *tlPay) BuildForm(data url.Values) string { func (api *tlPay) BuildForm(formUrl string, data url.Values) string {
htmlBegin := ` htmlBegin := `
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
@ -249,7 +260,7 @@ func (api *tlPay) BuildForm(data url.Values) string {
<meta charset="utf-8"> <meta charset="utf-8">
<script> <script>
window.onload = function() { window.onload = function() {
document.getElementById("auto-submit-form").submit(); //document.getElementById("auto-submit-form").submit();
}; };
</script> </script>
</head> </head>
@ -259,18 +270,16 @@ func (api *tlPay) BuildForm(data url.Values) string {
`</body> `</body>
</html> </html>
` `
return htmlBegin + api.buildFormHtml(data) + htmlEnd return htmlBegin + api.buildFormHtml(formUrl, data) + htmlEnd
} }
func (api *tlPay) buildFormHtml(data url.Values) string { func (api *tlPay) buildFormHtml(formUrl string, data url.Values) string {
payConfig := global.Config.TlPay
formUrl := payConfig.BaseUrl + "/apiweb/gateway/pay"
formHtml := "<form id=\"auto-submit-form\" action=\"" + formUrl + "\" method=\"POST\">" formHtml := "<form id=\"auto-submit-form\" action=\"" + formUrl + "\" method=\"POST\">"
for key, value := range data { for key, value := range data {
formHtml += "<input type=\"hidden\" name=\"" + key + "\" value=\"" + value[0] + "\">" formHtml += "<input type=\"hidden\" name=\"" + key + "\" value=\"" + value[0] + "\">"
} }
//formHtml += "<button type=\"submit\">提交</button>" formHtml += "<button type=\"submit\">提交</button>"
formHtml += "</form>" formHtml += "</form>"
return formHtml return formHtml
} }

@ -0,0 +1,35 @@
package param
type UnionOrderParam struct {
CusID string `json:"cusid" form:"cusid"`
AppID string `json:"appid" form:"appid"`
ReqTime string `json:"reqtime" form:"reqtime"`
ReqIp string `json:"reqip" form:"reqip"`
Version string `json:"version" form:"version"`
RandomStr string `json:"randomstr" form:"randomstr"`
SignType string `json:"signtype" form:"signtype"`
Sign string `json:"sign" form:"sign"`
ReqSn string `json:"reqsn" form:"reqsn"`
PayType string `json:"paytype" form:"paytype"`
TrxAmt string `json:"trxamt" form:"trxamt"`
FqNum string `json:"fqnum" form:"fqnum"`
Charset string `json:"charset" form:"charset"`
RetUrl string `json:"returl" form:"returl"`
NotifyUrl string `json:"notify_url" form:"notify_url"`
Body string `json:"body" form:"body"`
Remark string `json:"remark" form:"remark"`
ValidTime string `json:"validtime" form:"validtime"`
ExpireTime string `json:"expiretime" form:"expiretime"`
LimitPay string `json:"limit_pay" form:"limit_pay"`
GoodsTag string `json:"goods_tag" form:"goods_tag"`
BenefitDetail string `json:"benefitdetail" form:"benefitdetail"`
AsInfo string `json:"asinfo" form:"asinfo"`
SubBranch string `json:"subbranch" form:"subbranch"`
ExtendParams string `json:"extendparams" form:"extendparams"`
TrueName string `json:"truename" form:"truename"`
IdNo string `json:"idno" form:"idno"`
IsHide string `json:"ishide" form:"ishide"`
UnPid string `json:"unpid" form:"unpid"`
TermInfo string `json:"terminfo" form:"terminfo"`
}
Loading…
Cancel
Save