1 Star 0 Fork 4

yirenji/wxpay4go

forked from haming123/wxpay4go 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
wx_mch_native.go 1.11 KB
一键复制 编辑 原始数据 按行查看 历史
haming 提交于 2022-03-03 13:19 . init
package wxpay
import (
"crypto/rsa"
"crypto/x509"
"encoding/json"
"errors"
)
type MchNative struct {
WxPayMch
}
func NewMchNative(mchid, appid, mch_api_key string, pem_cert *x509.Certificate, pem_key *rsa.PrivateKey) *MchNative {
ent := &MchNative{}
ent.Appid = appid
ent.Mchid = mchid
ent.MchAPIKey = mch_api_key
ent.MchPrivateKey = pem_key
ent.MchCertificate = pem_cert
return ent
}
//支付统一下单
func (ent *MchNative)CreateOrder(data NativeOrderData) (string, error) {
var preq NativeOrderCreateReq
preq.Appid = ent.Appid
preq.Mchid = ent.Mchid
preq.NativeOrderData = data
preq.Sp_appid = ""
preq.Sp_mchid = ""
preq.NativeOrderData.Sub_mchid = ""
preq.NativeOrderData.Sub_appid = ""
data_body, _ := json.Marshal(preq)
var pret NativeOrderCreateRet
const url = "https://api.mch.weixin.qq.com/v3/pay/transactions/native"
result, err := WxPayPostV3(&ent.MchParam, url, data_body)
if err != nil {
return "", err
}
err = json.Unmarshal([]byte(result), &pret)
if err != nil {
return "", err
}
if pret.Code_url == "" {
return "", errors.New(pret.Return_msg)
}
return pret.Code_url, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/thinkphpbox/wxpay4go.git
git@gitee.com:thinkphpbox/wxpay4go.git
thinkphpbox
wxpay4go
wxpay4go
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385