PaymentCenter/app/services/thirdpay/ali.go

43 lines
1.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package thirdpay
import (
"PaymentCenter/app/data"
"PaymentCenter/app/http/entities/front"
"PaymentCenter/app/models/paychannelmodel"
"PaymentCenter/app/third/paymentService"
"context"
"fmt"
"github.com/go-pay/gopay/alipay"
"github.com/goccy/go-json"
"xorm.io/builder"
)
// 小程序支付 通过code换取网页授权access_tokenopenid,
func GetAliOauth(ctx context.Context, param front.GetAliOauthRequest) (result *alipay.OauthTokenInfo, err error) {
var (
has bool
payChannel = paychannelmodel.PayChannel{}
repo = data.NewPayChannelRepo(paychannelmodel.GetInstance().GetDb())
)
// 获取支付渠道的配置
has, err = repo.PayChannelGet(&payChannel, builder.Eq{"id": param.PayChannelId})
if err != nil {
return
} else if !has {
err = fmt.Errorf("获取支付渠道不存在")
return
}
// 配置支付的解析
aliConfig := paymentService.AliPay{}
err = json.Unmarshal([]byte(payChannel.ExtJson), &aliConfig)
if err != nil {
err = fmt.Errorf("解析支付渠道配置失败")
return
}
// 支付宝,获取小程序 授权信息 openid
result, err = paymentService.ALiGetOpenId(ctx, aliConfig, param.Code)
return
}