This commit is contained in:
邹宗楠
2025-04-27 10:17:40 +08:00
parent cf38acc037
commit 1a5a3ffc29
14 changed files with 920 additions and 156 deletions

View File

@@ -1,148 +1,14 @@
package tonglianpayapi
import (
"crypto/md5"
"fmt"
"net/http"
"sort"
"strings"
"git.rosy.net.cn/baseapi/platformapi"
"git.rosy.net.cn/baseapi/utils"
)
const (
prodURL = "https://vsp.allinpay.com/apiweb"
prodURL2 = "https://syb.allinpay.com/apiweb"
sepcAction = "unitorder/pay"
sepcAction2 = "h5unionpay/unionorder"
sigKey = "sign"
PayTypeWxXcx = "W06"
PayTypeWxCode = "W01"
PayTypeZfbApp = "A03"
PayTypeZfbQrcode = "A01"
PayTypeZfbJS = "A02"
PayTypeH5 = "H5"
ResponseCodeSuccess = "SUCCESS"
ResponseCodeFail = "FAIL"
)
type API struct {
appID string
cusID string
appKey string
client *http.Client
config *platformapi.APIConfig
}
type CreateUnitorderOrderParam struct {
CusID string `json:"cusid"`
AppID string `json:"appid"`
Trxamt int `json:"trxamt"` //交易金额 单位为分
Reqsn string `json:"reqsn"` //商户交易单号
NotifyUrl string `json:"notifyUrl"` //接收微信支付异步通知回调地址通知url必须为直接可访问的url不能携带参数。
Acct string `json:"acct"`
PayType string `json:"paytype"`
SubAppID string `json:"subAppID"`
}
type CreateUnitOrderOrderResult struct {
RetCode string `json:"retCode"`
RetMsg string `json:"retMsg"`
CusID string `json:"cusID"`
AppID string `json:"appID"`
TrxID string `json:"trxID"`
ChnltrxID string `json:"chnltrxID"`
Reqsn string `json:"reqsn"`
RandomStr string `json:"randomStr"`
TrxStatus string `json:"trxStatus"`
FinTime string `json:"finTime"`
ErrMsg string `json:"errMsg"`
PayInfo string `json:"payInfo"`
Sign string `json:"sign"`
}
type PayInfo struct {
AppID string `json:"appID"`
TimeStamp string `json:"timeStamp"`
NonceStr string `json:"nonceStr"`
Package string `json:"package"`
SignType string `json:"signType"`
PaySign string `json:"paySign"`
}
type PayRefundParam struct {
CusID string `json:"cusid"`
AppID string `json:"appid"`
Trxamt int `json:"trxamt"` //交易金额 单位为分
Reqsn string `json:"reqsn"` //商户交易单号
OldReqsn string `json:"oldReqsn"`
Remark string `json:"remark"`
RandomStr string `json:"randomStr"`
Sign string `json:"sign"`
TrxID string `json:"trxID"`
OldTrxID string `json:"oldTrxID"`
}
type PayRefundResult struct {
RetCode string `json:"retCode"`
RetMsg string `json:"retMsg"`
CusID string `json:"cusID"`
AppID string `json:"appID"`
TrxID string `json:"trxID"`
Reqsn string `json:"reqsn"`
TrxStatus string `json:"trxStatus"`
FinTime string `json:"finTime"`
ErrMsg string `json:"errMsg"`
RandomStr string `json:"randomStr"`
Sign string `json:"sign"`
Fee string `json:"fee"`
TrxCode string `json:"trxCode"`
}
type CreateH5UnitorderOrderParam struct {
Trxamt int `json:"trxamt"` //交易金额 单位为分
Reqsn string `json:"reqsn"` //商户交易单号
NotifyUrl string `json:"notifyUrl"` //接收微信支付异步通知回调地址通知url必须为直接可访问的url不能携带参数。
Charset string `json:"charset"`
Returl string `json:"returl"`
Body string `json:"body"`
}
func New(appID, appKey, cusID string, config ...*platformapi.APIConfig) *API {
curConfig := platformapi.DefAPIConfig
if len(config) > 0 {
curConfig = *config[0]
}
return &API{
appID: appID,
appKey: appKey,
cusID: cusID,
client: &http.Client{Timeout: curConfig.ClientTimeout},
config: &curConfig,
}
}
func (a *API) signParam(params map[string]interface{}) (sig string) {
var valueList []string
for k, v := range params {
if k != sigKey {
if str := fmt.Sprint(v); str != "" {
valueList = append(valueList, fmt.Sprintf("%s=%s", k, str))
}
}
}
valueList = append(valueList, fmt.Sprintf("key=%s", a.appKey))
sort.Sort(sort.StringSlice(valueList))
sig = strings.Join(valueList, "&")
binSig := md5.Sum([]byte(sig))
sig = fmt.Sprintf("%X", binSig)
return sig
}
func (a *API) AccessAPI(action string, bizParams map[string]interface{}) (retVal map[string]interface{}, err error) {
params := make(map[string]interface{})
params["appid"] = a.appID