1 Star 1 Fork 0

窦雪峰 / go-utils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
app.go 2.10 KB
一键复制 编辑 原始数据 按行查看 历史
窦雪峰 提交于 2022-08-19 16:52 . fix app wechaypay
/*
* @Author: i@douxuefeng.cn
* @Date: 2022-05-14 17:02:20
* @LastEditTime: 2022-08-19 16:49:27
* @LastEditors: i@douxuefeng.cn
* @Description:
* @FilePath: \go-utils\wechat\pay\app.go
*/
package pay
import (
"github.com/wechatpay-apiv3/wechatpay-go/core"
"github.com/wechatpay-apiv3/wechatpay-go/services/payments"
pay_app "github.com/wechatpay-apiv3/wechatpay-go/services/payments/app"
)
type app struct {
*PayConfig
}
func NewApp(cfg *PayConfig) *app {
return &app{cfg}
}
func (p *app) PrepayOrder(prepay OrderRequest) (*pay_app.PrepayWithRequestPaymentResponse, *core.APIResult, error) {
client, ctx, err := GetClient(p.PayConfig)
if err != nil {
return nil, nil, err
}
svc := pay_app.AppApiService{Client: client}
resp, result, err := svc.PrepayWithRequestPayment(ctx, pay_app.PrepayRequest{
Appid: core.String(p.AppAppid),
Mchid: core.String(p.MchId),
Description: core.String(prepay.Description),
OutTradeNo: core.String(prepay.OutTradeNo),
Attach: core.String(prepay.Attach),
NotifyUrl: core.String(p.Notify),
Amount: &pay_app.Amount{
Total: core.Int64(int64(prepay.Amount * 100)),
},
SceneInfo: &pay_app.SceneInfo{
PayerClientIp: core.String(prepay.ClientIp),
},
})
if err != nil {
return nil, nil, err
}
if err != nil {
return nil, nil, err
}
return resp, result, err
}
func (p *app) QueryOrderByTransactionId(transactionId string) (*payments.Transaction, *core.APIResult, error) {
client, ctx, err := GetClient(p.PayConfig)
if err != nil {
return nil, nil, err
}
svc := pay_app.AppApiService{Client: client}
return svc.QueryOrderById(ctx, pay_app.QueryOrderByIdRequest{
Mchid: core.String(p.MchId),
TransactionId: core.String(transactionId),
})
}
func (p *app) QueryOrderByOutTradeNo(outNo string) (*payments.Transaction, *core.APIResult, error) {
client, ctx, err := GetClient(p.PayConfig)
if err != nil {
return nil, nil, err
}
svc := pay_app.AppApiService{Client: client}
return svc.QueryOrderByOutTradeNo(ctx, pay_app.QueryOrderByOutTradeNoRequest{
Mchid: core.String(p.MchId),
OutTradeNo: core.String(outNo),
})
}
Go
1
https://gitee.com/douxuefeng/go-utils.git
git@gitee.com:douxuefeng/go-utils.git
douxuefeng
go-utils
go-utils
v0.2.6

搜索帮助