feat: 增加支付宝jsapi支付方式,支付宝回调处理单位元转分
This commit is contained in:
parent
7afe162f95
commit
9108c2bce9
|
@ -145,7 +145,6 @@ func (w *Pay) PayUrl() (url string) {
|
|||
}
|
||||
case common.PAY_CHANNEL_WECHAT_MINI:
|
||||
// 微信小程序支付
|
||||
|
||||
// 如果传openid,获取支付参数
|
||||
if w.PayParam.OpenId != "" {
|
||||
res = paymentService.PaymentService(*w.ctx, *thirdPay)
|
||||
|
@ -176,6 +175,10 @@ func (w *Pay) PayUrl() (url string) {
|
|||
}
|
||||
}
|
||||
|
||||
case common.PAY_CHANNEL_ALIPAY_JSAPI:
|
||||
// 支付宝jsapi支付
|
||||
res = paymentService.PaymentService(*w.ctx, *thirdPay)
|
||||
|
||||
default:
|
||||
w.PayCode = errorcode.PayChannelNotBuild
|
||||
return
|
||||
|
|
|
@ -14,6 +14,7 @@ var PayWayList = map[int]func(commonPayInfo *paymentService.PayOrderRequest, cha
|
|||
common.PAY_CHANNEL_ALIPAY_PC: AlipayWeb,
|
||||
common.PAY_CHANNEL_WECHAT_JSAPI: WechatJSAPI,
|
||||
common.PAY_CHANNEL_WECHAT_MINI: WechatJSAPI,
|
||||
common.PAY_CHANNEL_ALIPAY_JSAPI: AlipayWeb,
|
||||
}
|
||||
|
||||
func WechatH5(commonPayInfo *paymentService.PayOrderRequest, channel *paychannelmodel.PayChannel) error {
|
||||
|
|
|
@ -155,7 +155,15 @@ func ALiCallBack(notifyReq gopay.BodyMap, aliConfig AliPay) error {
|
|||
|
||||
// 拼装数据触发下游回调,触发下游回调
|
||||
orderId, _ := strconv.Atoi(notifyReq.Get("out_trade_no"))
|
||||
payerTotal, _ := strconv.Atoi(notifyReq.Get("buyer_pay_amount"))
|
||||
buyerPayAmount := notifyReq.Get("buyer_pay_amount") // 单位为元
|
||||
// 将字符串转换为浮点数,转为分
|
||||
buyerPayAmountFloat, err := strconv.ParseFloat(buyerPayAmount, 64)
|
||||
if err != nil {
|
||||
logger.Error(context.Background(), "ALiCallBack 发生错误", fmt.Sprintf("回调时,金额转换失败,失败原因:%s", err.Error()))
|
||||
return err
|
||||
}
|
||||
payerTotal := int(buyerPayAmountFloat * 100)
|
||||
|
||||
// 订单状态
|
||||
tradeStatus := notifyReq.Get("trade_status")
|
||||
errCode := 0
|
||||
|
@ -356,3 +364,38 @@ func AliCloseOrder(ctx context.Context, orderCloseRequest OrderCloseRequest) (Or
|
|||
OutTradeNo: int64(outTradeNo),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// 支付宝,jsapi支付, 返回支付宝交易号用于小程序支付
|
||||
func ALiJsApiPayInfo(c context.Context, payOrderRequest PayOrderRequest) (string, error) {
|
||||
// 初始化支付宝客户端
|
||||
aliClient, err := AliInitClient(payOrderRequest.Ali)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
// 初始化 BodyMap
|
||||
amount := float64(payOrderRequest.Amount) / 100.0
|
||||
|
||||
envConfig := config.GetConf()
|
||||
bm := make(gopay.BodyMap)
|
||||
bm.Set("out_trade_no", payOrderRequest.OrderId).
|
||||
Set("total_amount", amount).
|
||||
Set("subject", payOrderRequest.Description).
|
||||
Set("qr_pay_mode", "JSAPI_PAY").
|
||||
Set("op_app_id", payOrderRequest.Ali.AppId).
|
||||
Set("buyer_open_id", payOrderRequest.OpenId).
|
||||
Set("notify_url", fmt.Sprintf(envConfig.PayService.Host+payCommon.ALI_NOTIFY_URL_TEST+"%d", payOrderRequest.PayChannelId))
|
||||
if payOrderRequest.ReturnUrl != "" {
|
||||
bm.Set("return_url", payOrderRequest.ReturnUrl)
|
||||
}
|
||||
|
||||
aliRsp, err := aliClient.TradeCreate(c, bm)
|
||||
if err != nil {
|
||||
logger.Error(c, "ALiH5PayInfo 发生错误", fmt.Sprintf("错误信息:%s", err.Error()))
|
||||
if bizErr, ok := alipay.IsBizError(err); ok {
|
||||
return "", bizErr
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
|
||||
return aliRsp.Response.TradeNo, nil
|
||||
}
|
||||
|
|
|
@ -66,6 +66,9 @@ func PaymentService(c context.Context, payOrderRequest PayOrderRequest) PayOrder
|
|||
case payCommon.PAY_CHANNEL_ALIPAY_PC:
|
||||
// 支付宝PC支付
|
||||
info, err = ALiPCPayInfo(c, payOrderRequest)
|
||||
case payCommon.PAY_CHANNEL_ALIPAY_JSAPI:
|
||||
// 支付宝JSAPI支付
|
||||
info, err = ALiJsApiPayInfo(c, payOrderRequest)
|
||||
|
||||
default:
|
||||
payOrderResponse = PayOrderResponse{
|
||||
|
|
Loading…
Reference in New Issue