Skip to content

Commit

Permalink
v1.5.74 (#233)
Browse files Browse the repository at this point in the history
* v1.5.74
  • Loading branch information
iGoogle-ink authored Mar 19, 2022
1 parent fc2bcfa commit 1942e21
Show file tree
Hide file tree
Showing 43 changed files with 306 additions and 236 deletions.
4 changes: 2 additions & 2 deletions alipay/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestClient_PostAliPayAPISelfV2(t *testing.T) {
// biz_content
bm.SetBodyMap("biz_content", func(bz gopay.BodyMap) {
bz.Set("subject", "预创建创建订单")
bz.Set("out_trade_no", util.GetRandomString(32))
bz.Set("out_trade_no", util.RandomString(32))
bz.Set("total_amount", "100")
})

Expand All @@ -82,7 +82,7 @@ func TestClient_PostAliPayAPISelfV2(t *testing.T) {
func TestClient_PostAliPayAPISelf(t *testing.T) {
bm := make(gopay.BodyMap)
bm.Set("subject", "预创建创建订单")
bm.Set("out_trade_no", util.GetRandomString(32))
bm.Set("out_trade_no", util.RandomString(32))
bm.Set("total_amount", "100")

aliPsp := new(TradePrecreateResponse)
Expand Down
6 changes: 3 additions & 3 deletions alipay/payment_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestClient_TradePrecreate(t *testing.T) {
// 请求参数
bm := make(gopay.BodyMap)
bm.Set("subject", "预创建创建订单").
Set("out_trade_no", util.GetRandomString(32)).
Set("out_trade_no", util.RandomString(32)).
Set("total_amount", "0.01")

// 创建订单
Expand All @@ -39,7 +39,7 @@ func TestClient_TradeCreate(t *testing.T) {
bm := make(gopay.BodyMap)
bm.Set("subject", "创建订单").
Set("buyer_id", "2088802095984694").
Set("out_trade_no", util.GetRandomString(32)).
Set("out_trade_no", util.RandomString(32)).
Set("total_amount", "0.01")

// 创建订单
Expand Down Expand Up @@ -199,7 +199,7 @@ func TestClient_TradePageRefund(t *testing.T) {
bm := make(gopay.BodyMap)
bm.Set("out_trade_no", "GZ201909081743431443").
Set("refund_amount", "5").
Set("out_request_no", util.GetRandomString(32))
Set("out_request_no", util.RandomString(32))

// 发起退款请求
aliRsp, err := client.TradePageRefund(ctx, bm)
Expand Down
2 changes: 1 addition & 1 deletion alipay/zhima_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestZhimaCreditEpSceneAgreementCancel(t *testing.T) {
// 请求参数
bm := make(gopay.BodyMap)
bm.Set("credit_order_no", "zme20181106154144733795615964647")
bm.Set("out_order_no", util.GetRandomString(64))
bm.Set("out_order_no", util.RandomString(64))
bm.Set("biz_time", "2018-12-06 18:53:59")

aliRsp, err := client.ZhimaCreditEpSceneAgreementCancel(ctx, bm)
Expand Down
1 change: 0 additions & 1 deletion apple/notification_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func TestDecodeSignedPayload(t *testing.T) {
"signedDate":1646387008228
}
*/

// decode transactionInfo
transactionInfo, err := payload.DecodeTransactionInfo()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion body_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestBodyMapMarshalSlice(t *testing.T) {
bs, _ := json.Marshal(rs)

bm := make(BodyMap)
bm.Set("nonce_str", util.GetRandomString(32)).
bm.Set("nonce_str", util.RandomString(32)).
Set("transaction_id", "4208450740201411110007820472").
Set("out_order_no", "P20150806125346")

Expand Down
2 changes: 1 addition & 1 deletion constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const (
OK = "OK"
DebugOff = 0
DebugOn = 1
Version = "1.5.73"
Version = "1.5.74"
)

type DebugSwitch int8
2 changes: 1 addition & 1 deletion examples/wechat/wx_BatchQueryComment.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func BatchQueryComment() {

// 初始化参数结构体
bm := make(gopay.BodyMap)
bm.Set("nonce_str", util.GetRandomString(32)).
bm.Set("nonce_str", util.RandomString(32)).
Set("sign_type", wechat.SignType_HMAC_SHA256).
Set("begin_time", "20190120000000").
Set("end_time", "20190122174000").
Expand Down
2 changes: 1 addition & 1 deletion examples/wechat/wx_CloseOrder.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func CloseOrder() {
// 初始化参数结构体
bm := make(gopay.BodyMap)
bm.Set("out_trade_no", "MfZC2segKxh0bnJSELbvKNeH3d9oWvvQ").
Set("nonce_str", util.GetRandomString(32)).
Set("nonce_str", util.RandomString(32)).
Set("sign_type", wechat.SignType_MD5)

// 请求关闭订单,成功后得到结果
Expand Down
2 changes: 1 addition & 1 deletion examples/wechat/wx_DownloadBill.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func DownloadBill() {

// 初始化参数结构体
bm := make(gopay.BodyMap)
bm.Set("nonce_str", util.GetRandomString(32)).
bm.Set("nonce_str", util.RandomString(32)).
Set("sign_type", wechat.SignType_MD5).
Set("bill_date", "20190722").
Set("bill_type", "ALL")
Expand Down
2 changes: 1 addition & 1 deletion examples/wechat/wx_DownloadFundFlow.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func DownloadFundFlow() {

// 初始化参数结构体
bm := make(gopay.BodyMap)
bm.Set("nonce_str", util.GetRandomString(32)).
bm.Set("nonce_str", util.RandomString(32)).
Set("sign_type", wechat.SignType_HMAC_SHA256).
Set("bill_date", "20190122").
Set("account_type", "Basic")
Expand Down
4 changes: 2 additions & 2 deletions examples/wechat/wx_Micropay.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ func Micropay() {
// isProd:是否是正式环境
client := wechat.NewClient("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", false)

number := util.GetRandomString(32)
number := util.RandomString(32)
xlog.Debug("out_trade_no:", number)
// 初始化参数Map
bm := make(gopay.BodyMap)
bm.Set("nonce_str", util.GetRandomString(32)).
bm.Set("nonce_str", util.RandomString(32)).
Set("body", "扫用户付款码支付").
Set("out_trade_no", number).
Set("total_fee", 1).
Expand Down
2 changes: 1 addition & 1 deletion examples/wechat/wx_QueryOrder.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func QueryOrder() {
// 初始化参数结构体
bm := make(gopay.BodyMap)
bm.Set("out_trade_no", "GW201908091551421156").
Set("nonce_str", util.GetRandomString(32)).
Set("nonce_str", util.RandomString(32)).
Set("sign_type", wechat.SignType_MD5)

// 请求订单查询,成功后得到结果
Expand Down
2 changes: 1 addition & 1 deletion examples/wechat/wx_QueryRefund.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func QueryRefund() {
//Set("out_refund_no", "vk4264I1UQ3Hm3E4AKsavK8npylGSgQA092f9ckUxp8A2gXmnsLEdsupURVTcaC7").
//Set("transaction_id", "97HiM5j6kGmM2fk7fYMc8MgKhPnEQ5Rk").
//Set("refund_id", "97HiM5j6kGmM2fk7fYMc8MgKhPnEQ5Rk").
Set("nonce_str", util.GetRandomString(32)).
Set("nonce_str", util.RandomString(32)).
Set("sign_type", wechat.SignType_MD5)

//请求申请退款
Expand Down
4 changes: 2 additions & 2 deletions examples/wechat/wx_Refund.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ func Refund() {
// isProd:是否是正式环境
client := wechat.NewClient("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", false)

s := util.GetRandomString(64)
s := util.RandomString(64)
xlog.Debug("out_refund_no:", s)
// 初始化参数结构体
bm := make(gopay.BodyMap)
bm.Set("out_trade_no", "SdZBAqJHBQGKVwb7aMR2mUwC588NG2Sd").
Set("nonce_str", util.GetRandomString(32)).
Set("nonce_str", util.RandomString(32)).
Set("sign_type", wechat.SignType_MD5).
Set("out_refund_no", s).
Set("total_fee", 1).
Expand Down
2 changes: 1 addition & 1 deletion examples/wechat/wx_Reverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func Reverse() {

// 初始化参数Map
bm := make(gopay.BodyMap)
bm.Set("nonce_str", util.GetRandomString(32)).
bm.Set("nonce_str", util.RandomString(32)).
Set("out_trade_no", "6aDCor1nUcAihrV5JBlI09tLvXbUp02B").
Set("sign_type", wechat.SignType_MD5)

Expand Down
2 changes: 1 addition & 1 deletion examples/wechat/wx_ServiceApi.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func GetOpenIdByAuthCode() {
// apiKey:ApiKey
// authCode:用户授权码
// nonceStr:随即字符串
openIdRsp, err := wechat.GetOpenIdByAuthCode(ctx, "wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", "135127679952609396", util.GetRandomString(32))
openIdRsp, err := wechat.GetOpenIdByAuthCode(ctx, "wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", "135127679952609396", util.RandomString(32))
if err != nil {
xlog.Error("err:", err)
return
Expand Down
4 changes: 2 additions & 2 deletions examples/wechat/wx_Transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ func Transfer() {

// 初始化参数结构体
bm := make(gopay.BodyMap)
bm.Set("nonce_str", util.GetRandomString(32)).
Set("partner_trade_no", util.GetRandomString(32)).
bm.Set("nonce_str", util.RandomString(32)).
Set("partner_trade_no", util.RandomString(32)).
Set("openid", "o0Df70H2Q0fY8JXh1aFPIRyOBgu8").
Set("check_name", "FORCE_CHECK"). // NO_CHECK:不校验真实姓名 , FORCE_CHECK:强校验真实姓名
Set("re_user_name", "付明明"). // 收款用户真实姓名。 如果check_name设置为FORCE_CHECK,则必填用户真实姓名
Expand Down
4 changes: 2 additions & 2 deletions examples/wechat/wx_UnifiedOrder.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ func UnifiedOrder() {
//设置国家
client.SetCountry(wechat.China)

number := util.GetRandomString(32)
number := util.RandomString(32)
xlog.Debug("out_trade_no:", number)

//初始化参数Map
bm := make(gopay.BodyMap)
bm.Set("nonce_str", util.GetRandomString(32)).
bm.Set("nonce_str", util.RandomString(32)).
Set("body", "H5支付").
Set("out_trade_no", number).
Set("total_fee", 1).
Expand Down
11 changes: 10 additions & 1 deletion gopay_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package gopay

import (
"crypto/sha1"
"encoding/hex"
"encoding/xml"
"fmt"
"testing"

"github.com/go-pay/gopay/pkg/xlog"
Expand All @@ -11,14 +14,20 @@ func TestBodyMap_CheckParamsNull(t *testing.T) {
bm := make(BodyMap)
bm.Set("name", "jerry")
bm.Set("age", 2)
bm.Set("phone", "")
bm.Set("phone", "123")
bm.Set("pi", 3.1415926)

err := bm.CheckEmptyError("name", "age", "phone")
if err != nil {
xlog.Errorf("bm.CheckEmptyError():error:%+v", err)
return
}
h := sha1.New()
h.Write([]byte("golang"))
bs := h.Sum(nil)
_signature := fmt.Sprintf("%s", hex.EncodeToString(bs))
xlog.Info(_signature) // 771e417b9dcae54aead2f3cbbbff340787bc462f
// 771e417b9dcae54aead2f3cbbbff340787bc462f
}

func TestBodyMap_UnmarshalXML(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion paypal/order_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func TestCreateOrder(t *testing.T) {
var pus []*PurchaseUnit
var item = &PurchaseUnit{
ReferenceId: util.GetRandomString(16),
ReferenceId: util.RandomString(16),
Amount: &Amount{
CurrencyCode: "USD",
Value: "8",
Expand Down
43 changes: 43 additions & 0 deletions pkg/aes/aes_cbc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package aes

import (
"crypto/aes"
"crypto/cipher"
"errors"
)

// AES-CBC 加密数据
func CBCEncrypt(originData, key, iv []byte) ([]byte, error) {
return cbcEncrypt(originData, key, iv)
}

// AES-CBC 解密数据
func CBCDecrypt(secretData, key, iv []byte) ([]byte, error) {
return cbcDecrypt(secretData, key, iv)
}

func cbcEncrypt(originData, key, iv []byte) ([]byte, error) {
block, err := aes.NewCipher(key)
if err != nil {
return nil, err
}
originData = PKCS7Padding(originData, block.BlockSize())
secretData := make([]byte, len(originData))
blockMode := cipher.NewCBCEncrypter(block, iv[:block.BlockSize()])
blockMode.CryptBlocks(secretData, originData)
return secretData, nil
}

func cbcDecrypt(secretData, key, iv []byte) (originByte []byte, err error) {
block, err := aes.NewCipher(key)
if err != nil {
return nil, err
}
originByte = make([]byte, len(secretData))
blockMode := cipher.NewCBCDecrypter(block, iv[:block.BlockSize()])
blockMode.CryptBlocks(originByte, secretData)
if len(originByte) == 0 {
return nil, errors.New("blockMode.CryptBlocks error")
}
return PKCS7UnPadding(originByte), nil
}
47 changes: 0 additions & 47 deletions pkg/aes/aes_cbc_decrypt.go

This file was deleted.

43 changes: 0 additions & 43 deletions pkg/aes/aes_cbc_encrypt.go

This file was deleted.

Loading

0 comments on commit 1942e21

Please sign in to comment.