1 Star 1 Fork 0

窦雪峰/go-utils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
mini.go 2.20 KB
一键复制 编辑 原始数据 按行查看 历史
窦雪峰 提交于 2022-07-26 11:59 . fix amount
/*
* @Author: i@douxuefeng.cn
* @Date: 2022-05-14 17:03:17
* @LastEditTime: 2022-07-26 09:44:17
* @LastEditors: i@douxuefeng.cn
* @Description:
* @FilePath: \go-utils\wechat\pay\mini.go
*/
package pay
import (
"github.com/wechatpay-apiv3/wechatpay-go/core"
"github.com/wechatpay-apiv3/wechatpay-go/services/payments"
"github.com/wechatpay-apiv3/wechatpay-go/services/payments/jsapi"
)
type miniApi struct {
*PayConfig
}
func NewMiniApi(cfg *PayConfig) *miniApi {
return &miniApi{cfg}
}
/**
* @name: 预下单
* @description:
* @param {Prepay} prepay
* @return {*}
*/
func (p *miniApi) PrepayOrder(prepay OrderRequest) (*jsapi.PrepayWithRequestPaymentResponse, *core.APIResult, error) {
client, ctx, err := GetClient(p.PayConfig)
if err != nil {
return nil, nil, err
}
svc := jsapi.JsapiApiService{Client: client}
resp, result, err := svc.PrepayWithRequestPayment(ctx,
jsapi.PrepayRequest{
Appid: core.String(p.MiniAppid),
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: &jsapi.Amount{
Total: core.Int64(int64(prepay.Amount * 100)),
},
Payer: &jsapi.Payer{
Openid: core.String(prepay.Openid),
},
SceneInfo: &jsapi.SceneInfo{
PayerClientIp: core.String(prepay.ClientIp),
},
},
)
return resp, result, err
}
func (p *miniApi) QueryOrderByTransactionId(transactionId string) (*payments.Transaction, *core.APIResult, error) {
client, ctx, err := GetClient(p.PayConfig)
if err != nil {
return nil, nil, err
}
svc := jsapi.JsapiApiService{Client: client}
return svc.QueryOrderById(ctx, jsapi.QueryOrderByIdRequest{
Mchid: core.String(p.MchId),
TransactionId: core.String(transactionId),
})
}
func (p *miniApi) QueryOrderByOutTradeNo(outNo string) (*payments.Transaction, *core.APIResult, error) {
client, ctx, err := GetClient(p.PayConfig)
if err != nil {
return nil, nil, err
}
svc := jsapi.JsapiApiService{Client: client}
return svc.QueryOrderByOutTradeNo(ctx, jsapi.QueryOrderByOutTradeNoRequest{
Mchid: core.String(p.MchId),
OutTradeNo: core.String(outNo),
})
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/douxuefeng/go-utils.git
git@gitee.com:douxuefeng/go-utils.git
douxuefeng
go-utils
go-utils
v0.2.2

搜索帮助