Jerry 6 лет назад
Родитель
Сommit
70ce321baf
48 измененных файлов с 531 добавлено и 474 удалено
  1. 100 98
      alipay/alipay_client.go
  2. 7 5
      alipay/alipay_client_test.go
  3. 9 1
      alipay/alipay_model.go
  4. 20 18
      alipay/alipay_params.go
  5. 30 28
      alipay/alipay_service_api.go
  6. 21 16
      body_map.go
  7. 1 68
      constant.go
  8. 3 3
      doc.go
  9. 5 4
      examples/alipay/alipay_AliPaySystemOauthToken.go
  10. 2 1
      examples/alipay/alipay_AliPayTradeAppPay.go
  11. 2 1
      examples/alipay/alipay_AliPayTradeCancel.go
  12. 2 1
      examples/alipay/alipay_AliPayTradeClose.go
  13. 4 3
      examples/alipay/alipay_AliPayTradeCreate.go
  14. 4 3
      examples/alipay/alipay_AliPayTradeFastPayRefundQuery.go
  15. 6 5
      examples/alipay/alipay_AliPayTradeOrderSettle.go
  16. 2 1
      examples/alipay/alipay_AliPayTradePagePay.go
  17. 3 2
      examples/alipay/alipay_AliPayTradePay.go
  18. 2 1
      examples/alipay/alipay_AliPayTradePrecreate.go
  19. 2 1
      examples/alipay/alipay_AliPayTradeQuery.go
  20. 2 1
      examples/alipay/alipay_AliPayTradeRefund.go
  21. 2 1
      examples/alipay/alipay_AliPayTradeWapPay.go
  22. 2 1
      examples/alipay/alipay_AliPayUserCertifyOpenCertify.go
  23. 2 1
      examples/alipay/alipay_AliPayUserCertifyOpenInit.go
  24. 2 1
      examples/alipay/alipay_AliPayUserCertifyOpenQuery.go
  25. 2 1
      examples/alipay/alipay_AlipayFundTransToaccountTransfer.go
  26. 2 1
      examples/alipay/alipay_AlipayOpenAuthTokenApp.go
  27. 4 4
      examples/alipay/alipay_AlipayUserInfoShare.go
  28. 12 12
      examples/alipay/alipay_ServiceApi.go
  29. 2 1
      examples/alipay/alipay_ZhimaCreditScoreGet.go
  30. 3 2
      examples/wechat/wx_BatchQueryComment.go
  31. 3 2
      examples/wechat/wx_CloseOrder.go
  32. 3 2
      examples/wechat/wx_DownloadBill.go
  33. 3 2
      examples/wechat/wx_DownloadFundFlow.go
  34. 6 5
      examples/wechat/wx_Micropay.go
  35. 3 2
      examples/wechat/wx_QueryOrder.go
  36. 3 2
      examples/wechat/wx_QueryRefund.go
  37. 3 2
      examples/wechat/wx_Refund.go
  38. 3 2
      examples/wechat/wx_Reverse.go
  39. 21 20
      examples/wechat/wx_ServiceApi.go
  40. 2 1
      examples/wechat/wx_Transfer.go
  41. 8 7
      examples/wechat/wx_UnifiedOrder.go
  42. 1 1
      http_client.go
  43. 1 0
      qq_client.go
  44. 38 36
      wechat/wechat_client.go
  45. 34 27
      wechat/wechat_client_test.go
  46. 74 16
      wechat/wechat_model.go
  47. 20 18
      wechat/wechat_params.go
  48. 45 43
      wechat/wechat_service_api.go

+ 100 - 98
alipay_client.go → alipay/alipay_client.go

@@ -1,4 +1,4 @@
-package gopay
+package alipay
 
 import (
 	"encoding/json"
@@ -7,9 +7,11 @@ import (
 	"strings"
 	"sync"
 	"time"
+
+	"github.com/iGoogle-ink/gopay"
 )
 
-type AliPayClient struct {
+type Client struct {
 	AppId              string
 	PrivateKey         string
 	AppCertSN          string
@@ -30,8 +32,8 @@ type AliPayClient struct {
 //    appId:应用ID
 //    PrivateKey:应用私钥
 //    IsProd:是否是正式环境
-func NewAliPayClient(appId, privateKey string, isProd bool) (client *AliPayClient) {
-	return &AliPayClient{
+func NewClient(appId, privateKey string, isProd bool) (client *Client) {
+	return &Client{
 		AppId:      appId,
 		PrivateKey: privateKey,
 		IsProd:     isProd,
@@ -40,12 +42,12 @@ func NewAliPayClient(appId, privateKey string, isProd bool) (client *AliPayClien
 
 // alipay.trade.fastpay.refund.query(统一收单交易退款查询)
 //    文档地址:https://docs.open.alipay.com/api_1/alipay.trade.fastpay.refund.query
-func (a *AliPayClient) AliPayTradeFastPayRefundQuery(body BodyMap) (aliRsp *AliPayTradeFastpayRefundQueryResponse, err error) {
+func (a *Client) TradeFastPayRefundQuery(body gopay.BodyMap) (aliRsp *AliPayTradeFastpayRefundQueryResponse, err error) {
 	var (
 		bs []byte
 	)
-	if body.Get("out_trade_no") == null && body.Get("trade_no") == null {
-		return nil, errors.New("out_trade_no and trade_no are not allowed to be null at the same time")
+	if body.Get("out_trade_no") == gopay.NULL && body.Get("trade_no") == gopay.NULL {
+		return nil, errors.New("out_trade_no and trade_no are not allowed to be NULL at the same time")
 	}
 	if bs, err = a.doAliPay(body, "alipay.trade.fastpay.refund.query"); err != nil {
 		return
@@ -64,12 +66,12 @@ func (a *AliPayClient) AliPayTradeFastPayRefundQuery(body BodyMap) (aliRsp *AliP
 
 // alipay.trade.order.settle(统一收单交易结算接口)
 //    文档地址:https://docs.open.alipay.com/api_1/alipay.trade.order.settle
-func (a *AliPayClient) AliPayTradeOrderSettle(body BodyMap) (aliRsp *AliPayTradeOrderSettleResponse, err error) {
+func (a *Client) TradeOrderSettle(body gopay.BodyMap) (aliRsp *AliPayTradeOrderSettleResponse, err error) {
 	var (
 		bs []byte
 	)
-	if body.Get("out_request_no") == null || body.Get("trade_no") == null {
-		return nil, errors.New("out_request_no or trade_no are not allowed to be null")
+	if body.Get("out_request_no") == gopay.NULL || body.Get("trade_no") == gopay.NULL {
+		return nil, errors.New("out_request_no or trade_no are not allowed to be NULL")
 	}
 	if bs, err = a.doAliPay(body, "alipay.trade.order.settle"); err != nil {
 		return
@@ -88,12 +90,12 @@ func (a *AliPayClient) AliPayTradeOrderSettle(body BodyMap) (aliRsp *AliPayTrade
 
 // alipay.trade.create(统一收单交易创建接口)
 //    文档地址:https://docs.open.alipay.com/api_1/alipay.trade.create
-func (a *AliPayClient) AliPayTradeCreate(body BodyMap) (aliRsp *AliPayTradeCreateResponse, err error) {
+func (a *Client) TradeCreate(body gopay.BodyMap) (aliRsp *AliPayTradeCreateResponse, err error) {
 	var (
 		bs []byte
 	)
-	if body.Get("out_trade_no") == null && body.Get("buyer_id") == null {
-		return nil, errors.New("out_trade_no and buyer_id are not allowed to be null at the same time")
+	if body.Get("out_trade_no") == gopay.NULL && body.Get("buyer_id") == gopay.NULL {
+		return nil, errors.New("out_trade_no and buyer_id are not allowed to be NULL at the same time")
 	}
 	if bs, err = a.doAliPay(body, "alipay.trade.create"); err != nil {
 		return
@@ -112,12 +114,12 @@ func (a *AliPayClient) AliPayTradeCreate(body BodyMap) (aliRsp *AliPayTradeCreat
 
 // alipay.trade.close(统一收单交易关闭接口)
 //    文档地址:https://docs.open.alipay.com/api_1/alipay.trade.close
-func (a *AliPayClient) AliPayTradeClose(body BodyMap) (aliRsp *AliPayTradeCloseResponse, err error) {
+func (a *Client) AliPayTradeClose(body gopay.BodyMap) (aliRsp *AliPayTradeCloseResponse, err error) {
 	var (
 		bs []byte
 	)
-	if body.Get("out_trade_no") == null && body.Get("trade_no") == null {
-		return nil, errors.New("out_trade_no and trade_no are not allowed to be null at the same time")
+	if body.Get("out_trade_no") == gopay.NULL && body.Get("trade_no") == gopay.NULL {
+		return nil, errors.New("out_trade_no and trade_no are not allowed to be NULL at the same time")
 	}
 	if bs, err = a.doAliPay(body, "alipay.trade.close"); err != nil {
 		return
@@ -136,12 +138,12 @@ func (a *AliPayClient) AliPayTradeClose(body BodyMap) (aliRsp *AliPayTradeCloseR
 
 // alipay.trade.cancel(统一收单交易撤销接口)
 //    文档地址:https://docs.open.alipay.com/api_1/alipay.trade.cancel
-func (a *AliPayClient) AliPayTradeCancel(body BodyMap) (aliRsp *AliPayTradeCancelResponse, err error) {
+func (a *Client) AliPayTradeCancel(body gopay.BodyMap) (aliRsp *AliPayTradeCancelResponse, err error) {
 	var (
 		bs []byte
 	)
-	if body.Get("out_trade_no") == null && body.Get("trade_no") == null {
-		return nil, errors.New("out_trade_no and trade_no are not allowed to be null at the same time")
+	if body.Get("out_trade_no") == gopay.NULL && body.Get("trade_no") == gopay.NULL {
+		return nil, errors.New("out_trade_no and trade_no are not allowed to be NULL at the same time")
 	}
 	if bs, err = a.doAliPay(body, "alipay.trade.cancel"); err != nil {
 		return
@@ -160,12 +162,12 @@ func (a *AliPayClient) AliPayTradeCancel(body BodyMap) (aliRsp *AliPayTradeCance
 
 // alipay.trade.refund(统一收单交易退款接口)
 //    文档地址:https://docs.open.alipay.com/api_1/alipay.trade.refund
-func (a *AliPayClient) AliPayTradeRefund(body BodyMap) (aliRsp *AliPayTradeRefundResponse, err error) {
+func (a *Client) AliPayTradeRefund(body gopay.BodyMap) (aliRsp *AliPayTradeRefundResponse, err error) {
 	var (
 		bs []byte
 	)
-	if body.Get("out_trade_no") == null && body.Get("trade_no") == null {
-		return nil, errors.New("out_trade_no and trade_no are not allowed to be null at the same time")
+	if body.Get("out_trade_no") == gopay.NULL && body.Get("trade_no") == gopay.NULL {
+		return nil, errors.New("out_trade_no and trade_no are not allowed to be NULL at the same time")
 	}
 	if bs, err = a.doAliPay(body, "alipay.trade.refund"); err != nil {
 		return nil, err
@@ -184,12 +186,12 @@ func (a *AliPayClient) AliPayTradeRefund(body BodyMap) (aliRsp *AliPayTradeRefun
 
 // alipay.trade.refund(统一收单退款页面接口)
 //    文档地址:https://docs.open.alipay.com/api_1/alipay.trade.page.refund
-func (a *AliPayClient) AliPayTradePageRefund(body BodyMap) (aliRsp *AliPayTradePageRefundResponse, err error) {
+func (a *Client) AliPayTradePageRefund(body gopay.BodyMap) (aliRsp *AliPayTradePageRefundResponse, err error) {
 	var (
 		bs []byte
 	)
-	if body.Get("out_trade_no") == null && body.Get("trade_no") == null {
-		return nil, errors.New("out_trade_no and trade_no are not allowed to be null at the same time")
+	if body.Get("out_trade_no") == gopay.NULL && body.Get("trade_no") == gopay.NULL {
+		return nil, errors.New("out_trade_no and trade_no are not allowed to be NULL at the same time")
 	}
 	if bs, err = a.doAliPay(body, "	alipay.trade.page.refund"); err != nil {
 		return
@@ -208,10 +210,10 @@ func (a *AliPayClient) AliPayTradePageRefund(body BodyMap) (aliRsp *AliPayTradeP
 
 // alipay.trade.precreate(统一收单线下交易预创建)
 //    文档地址:https://docs.open.alipay.com/api_1/alipay.trade.precreate
-func (a *AliPayClient) AliPayTradePrecreate(body BodyMap) (aliRsp *AliPayTradePrecreateResponse, err error) {
+func (a *Client) AliPayTradePrecreate(body gopay.BodyMap) (aliRsp *AliPayTradePrecreateResponse, err error) {
 	var bs []byte
-	if body.Get("out_trade_no") == null {
-		return nil, errors.New("out_trade_no is not allowed to be null")
+	if body.Get("out_trade_no") == gopay.NULL {
+		return nil, errors.New("out_trade_no is not allowed to be NULL")
 	}
 	if bs, err = a.doAliPay(body, "alipay.trade.precreate"); err != nil {
 		return
@@ -230,10 +232,10 @@ func (a *AliPayClient) AliPayTradePrecreate(body BodyMap) (aliRsp *AliPayTradePr
 
 // alipay.trade.pay(统一收单交易支付接口)
 //    文档地址:https://docs.open.alipay.com/api_1/alipay.trade.pay
-func (a *AliPayClient) AliPayTradePay(body BodyMap) (aliRsp *AliPayTradePayResponse, err error) {
+func (a *Client) AliPayTradePay(body gopay.BodyMap) (aliRsp *AliPayTradePayResponse, err error) {
 	var bs []byte
-	if body.Get("out_trade_no") == null {
-		return nil, errors.New("out_trade_no is not allowed to be null")
+	if body.Get("out_trade_no") == gopay.NULL {
+		return nil, errors.New("out_trade_no is not allowed to be NULL")
 	}
 	if bs, err = a.doAliPay(body, "alipay.trade.pay"); err != nil {
 		return
@@ -252,12 +254,12 @@ func (a *AliPayClient) AliPayTradePay(body BodyMap) (aliRsp *AliPayTradePayRespo
 
 // alipay.trade.query(统一收单线下交易查询)
 //    文档地址:https://docs.open.alipay.com/api_1/alipay.trade.query
-func (a *AliPayClient) AliPayTradeQuery(body BodyMap) (aliRsp *AliPayTradeQueryResponse, err error) {
+func (a *Client) AliPayTradeQuery(body gopay.BodyMap) (aliRsp *AliPayTradeQueryResponse, err error) {
 	var (
 		bs []byte
 	)
-	if body.Get("out_trade_no") == null && body.Get("trade_no") == null {
-		return nil, errors.New("out_trade_no and trade_no are not allowed to be null at the same time")
+	if body.Get("out_trade_no") == gopay.NULL && body.Get("trade_no") == gopay.NULL {
+		return nil, errors.New("out_trade_no and trade_no are not allowed to be NULL at the same time")
 	}
 	if bs, err = a.doAliPay(body, "alipay.trade.query"); err != nil {
 		return
@@ -276,13 +278,13 @@ func (a *AliPayClient) AliPayTradeQuery(body BodyMap) (aliRsp *AliPayTradeQueryR
 
 // alipay.trade.app.pay(app支付接口2.0)
 //    文档地址:https://docs.open.alipay.com/api_1/alipay.trade.app.pay
-func (a *AliPayClient) AliPayTradeAppPay(body BodyMap) (payParam string, err error) {
+func (a *Client) AliPayTradeAppPay(body gopay.BodyMap) (payParam string, err error) {
 	var bs []byte
-	if body.Get("out_trade_no") == null {
-		return null, errors.New("out_trade_no is not allowed to be null")
+	if body.Get("out_trade_no") == gopay.NULL {
+		return gopay.NULL, errors.New("out_trade_no is not allowed to be NULL")
 	}
 	if bs, err = a.doAliPay(body, "alipay.trade.app.pay"); err != nil {
-		return null, err
+		return gopay.NULL, err
 	}
 	payParam = string(bs)
 	return
@@ -290,14 +292,14 @@ func (a *AliPayClient) AliPayTradeAppPay(body BodyMap) (payParam string, err err
 
 // alipay.trade.wap.pay(手机网站支付接口2.0)
 //    文档地址:https://docs.open.alipay.com/api_1/alipay.trade.wap.pay
-func (a *AliPayClient) AliPayTradeWapPay(body BodyMap) (payUrl string, err error) {
+func (a *Client) AliPayTradeWapPay(body gopay.BodyMap) (payUrl string, err error) {
 	var bs []byte
-	if body.Get("out_trade_no") == null {
-		return null, errors.New("out_trade_no is not allowed to be null")
+	if body.Get("out_trade_no") == gopay.NULL {
+		return gopay.NULL, errors.New("out_trade_no is not allowed to be NULL")
 	}
 	body.Set("product_code", "QUICK_WAP_WAY")
 	if bs, err = a.doAliPay(body, "alipay.trade.wap.pay"); err != nil {
-		return null, err
+		return gopay.NULL, err
 	}
 	payUrl = string(bs)
 	return
@@ -305,14 +307,14 @@ func (a *AliPayClient) AliPayTradeWapPay(body BodyMap) (payUrl string, err error
 
 // alipay.trade.page.pay(统一收单下单并支付页面接口)
 //    文档地址:https://docs.open.alipay.com/api_1/alipay.trade.page.pay
-func (a *AliPayClient) AliPayTradePagePay(body BodyMap) (payUrl string, err error) {
+func (a *Client) AliPayTradePagePay(body gopay.BodyMap) (payUrl string, err error) {
 	var bs []byte
-	if body.Get("out_trade_no") == null {
-		return null, errors.New("out_trade_no is not allowed to be null")
+	if body.Get("out_trade_no") == gopay.NULL {
+		return gopay.NULL, errors.New("out_trade_no is not allowed to be NULL")
 	}
 	body.Set("product_code", "FAST_INSTANT_TRADE_PAY")
 	if bs, err = a.doAliPay(body, "alipay.trade.page.pay"); err != nil {
-		return null, err
+		return gopay.NULL, err
 	}
 	payUrl = string(bs)
 	return
@@ -320,10 +322,10 @@ func (a *AliPayClient) AliPayTradePagePay(body BodyMap) (payUrl string, err erro
 
 // alipay.fund.trans.toaccount.transfer(单笔转账到支付宝账户接口)
 //    文档地址:https://docs.open.alipay.com/api_28/alipay.fund.trans.toaccount.transfer
-func (a *AliPayClient) AliPayFundTransToaccountTransfer(body BodyMap) (aliRsp *AliPayFundTransToaccountTransferResponse, err error) {
+func (a *Client) AliPayFundTransToaccountTransfer(body gopay.BodyMap) (aliRsp *AliPayFundTransToaccountTransferResponse, err error) {
 	var bs []byte
-	if body.Get("out_biz_no") == null {
-		return nil, errors.New("out_biz_no is not allowed to be null")
+	if body.Get("out_biz_no") == gopay.NULL {
+		return nil, errors.New("out_biz_no is not allowed to be NULL")
 	}
 	if bs, err = a.doAliPay(body, "alipay.fund.trans.toaccount.transfer"); err != nil {
 		return
@@ -342,28 +344,28 @@ func (a *AliPayClient) AliPayFundTransToaccountTransfer(body BodyMap) (aliRsp *A
 
 // alipay.trade.orderinfo.sync(支付宝订单信息同步接口)
 //    文档地址:https://docs.open.alipay.com/api_1/alipay.trade.orderinfo.sync
-func (a *AliPayClient) AliPayTradeOrderinfoSync(body BodyMap) {
+func (a *Client) AliPayTradeOrderinfoSync(body gopay.BodyMap) {
 
 }
 
 // alipay.system.oauth.token(换取授权访问令牌)
 //    文档地址:https://docs.open.alipay.com/api_9/alipay.system.oauth.token
-func (a *AliPayClient) AliPaySystemOauthToken(body BodyMap) (aliRsp *AliPaySystemOauthTokenResponse, err error) {
+func (a *Client) SystemOauthToken(body gopay.BodyMap) (aliRsp *AliPaySystemOauthTokenResponse, err error) {
 	var bs []byte
-	if body.Get("grant_type") == null {
-		return nil, errors.New("grant_type is not allowed to be null")
+	if body.Get("grant_type") == gopay.NULL {
+		return nil, errors.New("grant_type is not allowed to be NULL")
 	}
-	if body.Get("code") == null && body.Get("refresh_token") == null {
-		return nil, errors.New("code and refresh_token are not allowed to be null at the same time")
+	if body.Get("code") == gopay.NULL && body.Get("refresh_token") == gopay.NULL {
+		return nil, errors.New("code and refresh_token are not allowed to be NULL at the same time")
 	}
-	if bs, err = aliPaySystemOauthToken(a.AppId, a.PrivateKey, body, "alipay.system.oauth.token", a.IsProd); err != nil {
+	if bs, err = systemOauthToken(a.AppId, a.PrivateKey, body, "alipay.system.oauth.token", a.IsProd); err != nil {
 		return
 	}
 	aliRsp = new(AliPaySystemOauthTokenResponse)
 	if err = json.Unmarshal(bs, aliRsp); err != nil {
 		return nil, err
 	}
-	if aliRsp.Response.AccessToken == null {
+	if aliRsp.Response.AccessToken == gopay.NULL {
 		info := aliRsp.ErrorResponse
 		return nil, fmt.Errorf(`{"code":"%s","msg":"%s","sub_code":"%s","sub_msg":"%s"}`, info.Code, info.Msg, info.SubCode, info.SubMsg)
 	}
@@ -374,7 +376,7 @@ func (a *AliPayClient) AliPaySystemOauthToken(body BodyMap) (aliRsp *AliPaySyste
 // alipay.user.info.share(支付宝会员授权信息查询接口)
 //    body:此接口无需body参数
 //    文档地址:https://docs.open.alipay.com/api_2/alipay.user.info.share
-func (a *AliPayClient) AliPayUserInfoShare() (aliRsp *AliPayUserInfoShareResponse, err error) {
+func (a *Client) AliPayUserInfoShare() (aliRsp *AliPayUserInfoShareResponse, err error) {
 	var bs []byte
 	if bs, err = a.doAliPay(nil, "alipay.user.info.share"); err != nil {
 		return nil, err
@@ -393,13 +395,13 @@ func (a *AliPayClient) AliPayUserInfoShare() (aliRsp *AliPayUserInfoShareRespons
 
 // alipay.open.auth.token.app(换取应用授权令牌)
 //    文档地址:https://docs.open.alipay.com/api_9/alipay.open.auth.token.app
-func (a *AliPayClient) AliPayOpenAuthTokenApp(body BodyMap) (aliRsp *AliPayOpenAuthTokenAppResponse, err error) {
+func (a *Client) AliPayOpenAuthTokenApp(body gopay.BodyMap) (aliRsp *AliPayOpenAuthTokenAppResponse, err error) {
 	var bs []byte
-	if body.Get("grant_type") == null {
-		return nil, errors.New("grant_type is not allowed to be null")
+	if body.Get("grant_type") == gopay.NULL {
+		return nil, errors.New("grant_type is not allowed to be NULL")
 	}
-	if body.Get("code") == null && body.Get("refresh_token") == null {
-		return nil, errors.New("code and refresh_token are not allowed to be null at the same time")
+	if body.Get("code") == gopay.NULL && body.Get("refresh_token") == gopay.NULL {
+		return nil, errors.New("code and refresh_token are not allowed to be NULL at the same time")
 	}
 	if bs, err = a.doAliPay(body, "alipay.open.auth.token.app"); err != nil {
 		return
@@ -418,15 +420,15 @@ func (a *AliPayClient) AliPayOpenAuthTokenApp(body BodyMap) (aliRsp *AliPayOpenA
 
 // zhima.credit.score.get(芝麻分)
 //    文档地址:https://docs.open.alipay.com/api_8/zhima.credit.score.get
-func (a *AliPayClient) ZhimaCreditScoreGet(body BodyMap) (aliRsp *ZhimaCreditScoreGetResponse, err error) {
+func (a *Client) ZhimaCreditScoreGet(body gopay.BodyMap) (aliRsp *ZhimaCreditScoreGetResponse, err error) {
 	var (
 		bs []byte
 	)
-	if body.Get("product_code") == null {
+	if body.Get("product_code") == gopay.NULL {
 		body.Set("product_code", "w1010100100000000001")
 	}
-	if body.Get("transaction_id") == null {
-		return nil, errors.New("transaction_id is not allowed to be null")
+	if body.Get("transaction_id") == gopay.NULL {
+		return nil, errors.New("transaction_id is not allowed to be NULL")
 	}
 	if bs, err = a.doAliPay(body, "zhima.credit.score.get"); err != nil {
 		return
@@ -445,21 +447,21 @@ func (a *AliPayClient) ZhimaCreditScoreGet(body BodyMap) (aliRsp *ZhimaCreditSco
 
 // alipay.user.certify.open.initialize(身份认证初始化服务)
 //    文档地址:https://docs.open.alipay.com/api_2/alipay.user.certify.open.initialize
-func (a *AliPayClient) AliPayUserCertifyOpenInit(body BodyMap) (aliRsp *AliPayUserCertifyOpenInitResponse, err error) {
+func (a *Client) AliPayUserCertifyOpenInit(body gopay.BodyMap) (aliRsp *AliPayUserCertifyOpenInitResponse, err error) {
 	var (
 		bs []byte
 	)
-	if body.Get("biz_code") == null {
-		return nil, errors.New("biz_code is not allowed to be null")
+	if body.Get("biz_code") == gopay.NULL {
+		return nil, errors.New("biz_code is not allowed to be NULL")
 	}
-	if body.Get("outer_order_no") == null {
-		return nil, errors.New("outer_order_no is not allowed to be null")
+	if body.Get("outer_order_no") == gopay.NULL {
+		return nil, errors.New("outer_order_no is not allowed to be NULL")
 	}
-	if body.Get("identity_param") == null {
-		return nil, errors.New("identity_param is not allowed to be null")
+	if body.Get("identity_param") == gopay.NULL {
+		return nil, errors.New("identity_param is not allowed to be NULL")
 	}
-	if body.Get("merchant_config") == null {
-		return nil, errors.New("merchant_config is not allowed to be null")
+	if body.Get("merchant_config") == gopay.NULL {
+		return nil, errors.New("merchant_config is not allowed to be NULL")
 	}
 	if bs, err = a.doAliPay(body, "alipay.user.certify.open.initialize"); err != nil {
 		return
@@ -479,15 +481,15 @@ func (a *AliPayClient) AliPayUserCertifyOpenInit(body BodyMap) (aliRsp *AliPayUs
 // alipay.user.certify.open.certify(身份认证开始认证)
 //    API文档地址:https://docs.open.alipay.com/api_2/alipay.user.certify.open.certify
 //    产品文档地址:https://docs.open.alipay.com/20181012100420932508/quickstart
-func (a *AliPayClient) AliPayUserCertifyOpenCertify(body BodyMap) (certifyUrl string, err error) {
+func (a *Client) AliPayUserCertifyOpenCertify(body gopay.BodyMap) (certifyUrl string, err error) {
 	var (
 		bs []byte
 	)
-	if body.Get("certify_id") == null {
-		return null, errors.New("certify_id is not allowed to be null")
+	if body.Get("certify_id") == gopay.NULL {
+		return gopay.NULL, errors.New("certify_id is not allowed to be NULL")
 	}
 	if bs, err = a.doAliPay(body, "alipay.user.certify.open.certify"); err != nil {
-		return null, err
+		return gopay.NULL, err
 	}
 	certifyUrl = string(bs)
 	return
@@ -495,12 +497,12 @@ func (a *AliPayClient) AliPayUserCertifyOpenCertify(body BodyMap) (certifyUrl st
 
 // alipay.user.certify.open.query(身份认证记录查询)
 //    文档地址:https://docs.open.alipay.com/api_2/alipay.user.certify.open.query
-func (a *AliPayClient) AliPayUserCertifyOpenQuery(body BodyMap) (aliRsp *AliPayUserCertifyOpenQueryResponse, err error) {
+func (a *Client) AliPayUserCertifyOpenQuery(body gopay.BodyMap) (aliRsp *AliPayUserCertifyOpenQueryResponse, err error) {
 	var (
 		bs []byte
 	)
-	if body.Get("certify_id") == null {
-		return nil, errors.New("certify_id is not allowed to be null")
+	if body.Get("certify_id") == gopay.NULL {
+		return nil, errors.New("certify_id is not allowed to be NULL")
 	}
 	if bs, err = a.doAliPay(body, "alipay.user.certify.open.query"); err != nil {
 		return
@@ -518,7 +520,7 @@ func (a *AliPayClient) AliPayUserCertifyOpenQuery(body BodyMap) (aliRsp *AliPayU
 }
 
 // 向支付宝发送请求
-func (a *AliPayClient) doAliPay(body BodyMap, method string) (bs []byte, err error) {
+func (a *Client) doAliPay(body gopay.BodyMap, method string) (bs []byte, err error) {
 	var (
 		bodyStr, sign, url string
 		bodyBs             []byte
@@ -529,64 +531,64 @@ func (a *AliPayClient) doAliPay(body BodyMap, method string) (bs []byte, err err
 		}
 		bodyStr = string(bodyBs)
 	}
-	pubBody := make(BodyMap)
+	pubBody := make(gopay.BodyMap)
 	pubBody.Set("app_id", a.AppId)
 	pubBody.Set("method", method)
 	pubBody.Set("format", "JSON")
-	if a.AppCertSN != null {
+	if a.AppCertSN != gopay.NULL {
 		a.mu.RLock()
 		pubBody.Set("app_cert_sn", a.AppCertSN)
 		a.mu.RUnlock()
 	}
-	if a.AliPayRootCertSN != null {
+	if a.AliPayRootCertSN != gopay.NULL {
 		a.mu.RLock()
 		pubBody.Set("alipay_root_cert_sn", a.AliPayRootCertSN)
 		a.mu.RUnlock()
 	}
-	if a.ReturnUrl != null {
+	if a.ReturnUrl != gopay.NULL {
 		a.mu.RLock()
 		pubBody.Set("return_url", a.ReturnUrl)
 		a.mu.RUnlock()
 	}
-	if a.Charset == null {
+	if a.Charset == gopay.NULL {
 		pubBody.Set("charset", "utf-8")
 	} else {
 		a.mu.RLock()
 		pubBody.Set("charset", a.Charset)
 		a.mu.RUnlock()
 	}
-	if a.SignType == null {
+	if a.SignType == gopay.NULL {
 		pubBody.Set("sign_type", "RSA2")
 	} else {
 		a.mu.RLock()
 		pubBody.Set("sign_type", a.SignType)
 		a.mu.RUnlock()
 	}
-	pubBody.Set("timestamp", time.Now().Format(TimeLayout))
+	pubBody.Set("timestamp", time.Now().Format(gopay.TimeLayout))
 	pubBody.Set("version", "1.0")
-	if a.NotifyUrl != null {
+	if a.NotifyUrl != gopay.NULL {
 		a.mu.RLock()
 		pubBody.Set("notify_url", a.NotifyUrl)
 		a.mu.RUnlock()
 	}
-	if a.AppAuthToken != null {
+	if a.AppAuthToken != gopay.NULL {
 		a.mu.RLock()
 		pubBody.Set("app_auth_token", a.AppAuthToken)
 		a.mu.RUnlock()
 	}
-	if a.AuthToken != null {
+	if a.AuthToken != gopay.NULL {
 		a.mu.RLock()
 		pubBody.Set("auth_token", a.AuthToken)
 		a.mu.RUnlock()
 	}
-	if bodyStr != null {
+	if bodyStr != gopay.NULL {
 		pubBody.Set("biz_content", bodyStr)
 	}
 	if sign, err = getRsaSign(pubBody, pubBody.Get("sign_type"), FormatPrivateKey(a.PrivateKey)); err != nil {
 		return
 	}
 	pubBody.Set("sign", sign)
-	param := FormatAliPayURLParam(pubBody)
+	param := FormatURLParam(pubBody)
 	if method == "alipay.trade.app.pay" {
 		return []byte(param), nil
 	}
@@ -604,13 +606,13 @@ func (a *AliPayClient) doAliPay(body BodyMap, method string) (bs []byte, err err
 			return []byte(zfbBaseUrl + "?" + param), nil
 		}
 	}
-	httpClient := NewHttpClient()
+	httpClient := gopay.NewHttpClient()
 	if !a.IsProd {
 		url = zfbSandboxBaseUrlUtf8
 	} else {
 		url = zfbBaseUrlUtf8
 	}
-	res, bs, errs := httpClient.Type(TypeForm).Post(url).SendString(param).EndBytes()
+	res, bs, errs := httpClient.Type(gopay.TypeForm).Post(url).SendString(param).EndBytes()
 	if len(errs) > 0 {
 		return nil, errs[0]
 	}

+ 7 - 5
alipay_client_test.go → alipay/alipay_client_test.go

@@ -1,10 +1,12 @@
-package gopay
+package alipay
 
 import (
 	"encoding/json"
 	"fmt"
 	"strings"
 	"testing"
+
+	"github.com/iGoogle-ink/gopay"
 )
 
 type List struct {
@@ -40,7 +42,7 @@ type People struct {
 }
 
 func TestAliPayParams(t *testing.T) {
-	bodyMap := make(BodyMap)
+	bodyMap := make(gopay.BodyMap)
 
 	//people := new(People)
 	//people.Name = "Jerry"
@@ -57,7 +59,7 @@ func TestSyncVerifyAliPaySign(t *testing.T) {
 	signData := `{"code":"10000","msg":"Success","buyer_logon_id":"854***@qq.com","buyer_pay_amount":"0.01","buyer_user_id":"2088102363632794","fund_bill_list":[{"amount":"0.01","fund_channel":"PCREDIT"}],"gmt_payment":"2019-08-29 20:14:05","invoice_amount":"0.01","out_trade_no":"GZ201901301040361012","point_amount":"0.00","receipt_amount":"0.01","total_amount":"0.01","trade_no":"2019082922001432790585537960"}`
 	sign := "bk3SzX0CZRI811IJioS2XKQHcgMixUT8mYyGQj+vcOAQas7GIYi6LpykqqSc3m7+yvqoG0TdX/c2JjYnpw/J53JxtC2IC4vsLuIPIgghVo5qafsfSxEJ22w20RZDatI2dYqFVcj8Jp+4aesQ8zMMNw7cX9NLyk7kw3DecYeyQp+zrZMueZPqLh88Z+54G+e6QuSU++0ouqQVd4PkpPqy6YI+8MdMUX4Ve0jOQxMmYH8BC6n5ZsTH/uEaLEtzYVZdSw/xdSQ7K1SH73aEH8XbRYx6rL7RkKksrdvhezX+ThDjQ+fTWjvNFrGcg3fmqXRy2elvoalu+BQmqlkWWjEJYA=="
 	aliPayPublicKey := "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAp8gueNlkbiDidz6FBQEBpqoRgH8h7JtsPtYW0nzAqy1MME4mFnDSMfSKlreUomS3a55gmBopL1eF4/Km/dEnaL5tCY9+24SKn1D4iyls+lvz/ZjvUjVwxoUYBh8kkcxMZSDeDz8//o+9qZTrICVP2a4sBB8T0XmU4gxfw8FsmtoomBH1nLk3AO7wgRN2a3+SRSAmxrhIGDmF1lljSlhY32eJpJ2TZQKaWNW+7yDBU/0Wt3kQVY84vr14yYagnSCiIfqyVFqePayRtmVJDr5qvSXr51tdqs2zKZCu+26X7JAF4BSsaq4gmY5DmDTm4TohCnBduI1+bPGD+igVmtl05wIDAQAB"
-	pKey := FormatAliPayPublicKey(aliPayPublicKey)
+	pKey := FormatPublicKey(aliPayPublicKey)
 	err := verifyAliPaySign(signData, sign, "RSA2", pKey)
 	if err != nil {
 		fmt.Println("err:", err)
@@ -66,7 +68,7 @@ func TestSyncVerifyAliPaySign(t *testing.T) {
 
 func TestVerifyAliPaySign(t *testing.T) {
 	// 测试,假数据,无法验签通过
-	bm := make(BodyMap)
+	bm := make(gopay.BodyMap)
 	bm.Set("sign", "kPbQIjX+xQc8F0/A6/AocELIjhhZnGbcBN6G4MM/HmfWL4ZiHM6fWl5NQhzXJusaklZ1LFuMo+lHQUELAYeugH8LYFvxnNajOvZhuxNFbN2LhF0l/KL8ANtj8oyPM4NN7Qft2kWJTDJUpQOzCzNnV9hDxh5AaT9FPqRS6ZKxnzM=")
 	bm.Set("sign_type", "RSA2")
 	bm.Set("total_amount", "2.00")
@@ -88,7 +90,7 @@ func TestVerifyAliPaySign(t *testing.T) {
 	bm.Set("seller_id", "2088102119685838")
 	bm.Set("notify_id", "4a91b7a78a503640467525113fb7d8bg8e")
 
-	ok, err := VerifyAliPaySign("aliPayPublicKey", bm)
+	ok, err := VerifySign("aliPayPublicKey", bm)
 	if err != nil {
 		fmt.Println("err:", err)
 		return

+ 9 - 1
alipay_rsp.go → alipay/alipay_model.go

@@ -1,4 +1,12 @@
-package gopay
+package alipay
+
+const (
+	// URL
+	zfbBaseUrl            = "https://openapi.alipay.com/gateway.do"
+	zfbSandboxBaseUrl     = "https://openapi.alipaydev.com/gateway.do"
+	zfbBaseUrlUtf8        = "https://openapi.alipay.com/gateway.do?charset=utf-8"
+	zfbSandboxBaseUrlUtf8 = "https://openapi.alipaydev.com/gateway.do?charset=utf-8"
+)
 
 type AliPayNotifyRequest struct {
 	NotifyTime        string                   `json:"notify_time,omitempty"`

+ 20 - 18
alipay_params.go → alipay/alipay_params.go

@@ -1,4 +1,4 @@
-package gopay
+package alipay
 
 import (
 	"crypto"
@@ -13,6 +13,8 @@ import (
 	"fmt"
 	"hash"
 	"net/url"
+
+	"github.com/iGoogle-ink/gopay"
 )
 
 //	AppId      string `json:"app_id"`      //支付宝分配给开发者的应用ID
@@ -39,7 +41,7 @@ type OpenApiRoyaltyDetailInfoPojo struct {
 
 // 设置 应用公钥证书SN
 //    appCertSN:应用公钥证书SN,通过 gopay.GetCertSN() 获取
-func (a *AliPayClient) SetAppCertSN(appCertSN string) (client *AliPayClient) {
+func (a *Client) SetAppCertSN(appCertSN string) (client *Client) {
 	a.mu.Lock()
 	a.AppCertSN = appCertSN
 	a.mu.Unlock()
@@ -48,7 +50,7 @@ func (a *AliPayClient) SetAppCertSN(appCertSN string) (client *AliPayClient) {
 
 // 设置 支付宝公钥证书SN
 //    aliPayPublicCertSN:支付宝公钥证书SN,通过 gopay.GetCertSN() 获取
-func (a *AliPayClient) SetAliPayPublicCertSN(aliPayPublicCertSN string) (client *AliPayClient) {
+func (a *Client) SetAliPayPublicCertSN(aliPayPublicCertSN string) (client *Client) {
 	a.mu.Lock()
 	a.AliPayPublicCertSN = aliPayPublicCertSN
 	a.mu.Unlock()
@@ -57,7 +59,7 @@ func (a *AliPayClient) SetAliPayPublicCertSN(aliPayPublicCertSN string) (client
 
 // 设置 支付宝CA根证书SN
 //    aliPayRootCertSN:支付宝CA根证书SN,通过 gopay.GetCertSN() 获取
-func (a *AliPayClient) SetAliPayRootCertSN(aliPayRootCertSN string) (client *AliPayClient) {
+func (a *Client) SetAliPayRootCertSN(aliPayRootCertSN string) (client *Client) {
 	a.mu.Lock()
 	a.AliPayRootCertSN = aliPayRootCertSN
 	a.mu.Unlock()
@@ -66,7 +68,7 @@ func (a *AliPayClient) SetAliPayRootCertSN(aliPayRootCertSN string) (client *Ali
 
 // 设置 app_cert_sn 通过应用公钥证书路径
 //    appCertPath:应用公钥证书路径
-func (a *AliPayClient) SetAppCertSnByPath(appCertPath string) (client *AliPayClient, err error) {
+func (a *Client) SetAppCertSnByPath(appCertPath string) (client *Client, err error) {
 	sn, err := GetCertSN(appCertPath)
 	if err != nil {
 		return a, fmt.Errorf("get app_cert_sn return err, but alse return alipay client. err: %v", err)
@@ -79,7 +81,7 @@ func (a *AliPayClient) SetAppCertSnByPath(appCertPath string) (client *AliPayCli
 
 // 设置 alipay_cert_sn 通过 支付宝公钥证书文件路径
 //    aliPayPublicCertPath:支付宝公钥证书文件路径
-func (a *AliPayClient) SetAliPayPublicCertSnByPath(aliPayPublicCertPath string) (client *AliPayClient, err error) {
+func (a *Client) SetAliPayPublicCertSnByPath(aliPayPublicCertPath string) (client *Client, err error) {
 	sn, err := GetCertSN(aliPayPublicCertPath)
 	if err != nil {
 		return a, fmt.Errorf("get alipay_cert_sn return err, but alse return alipay client. err: %v", err)
@@ -92,7 +94,7 @@ func (a *AliPayClient) SetAliPayPublicCertSnByPath(aliPayPublicCertPath string)
 
 // 设置 alipay_root_cert_sn 通过支付宝CA根证书文件路径
 //    aliPayRootCertPath:支付宝CA根证书文件路径
-func (a *AliPayClient) SetAliPayRootCertSnByPath(aliPayRootCertPath string) (client *AliPayClient, err error) {
+func (a *Client) SetAliPayRootCertSnByPath(aliPayRootCertPath string) (client *Client, err error) {
 	sn, err := GetCertSN(aliPayRootCertPath)
 	if err != nil {
 		return a, fmt.Errorf("get alipay_root_cert_sn return err, but alse return alipay client. err: %v", err)
@@ -104,7 +106,7 @@ func (a *AliPayClient) SetAliPayRootCertSnByPath(aliPayRootCertPath string) (cli
 }
 
 // 设置支付后的ReturnUrl
-func (a *AliPayClient) SetReturnUrl(url string) (client *AliPayClient) {
+func (a *Client) SetReturnUrl(url string) (client *Client) {
 	a.mu.Lock()
 	a.ReturnUrl = url
 	a.mu.Unlock()
@@ -112,7 +114,7 @@ func (a *AliPayClient) SetReturnUrl(url string) (client *AliPayClient) {
 }
 
 // 设置支付宝服务器主动通知商户服务器里指定的页面http/https路径。
-func (a *AliPayClient) SetNotifyUrl(url string) (client *AliPayClient) {
+func (a *Client) SetNotifyUrl(url string) (client *Client) {
 	a.mu.Lock()
 	a.NotifyUrl = url
 	a.mu.Unlock()
@@ -120,9 +122,9 @@ func (a *AliPayClient) SetNotifyUrl(url string) (client *AliPayClient) {
 }
 
 // 设置编码格式,如utf-8,gbk,gb2312等,默认推荐使用 utf-8
-func (a *AliPayClient) SetCharset(charset string) (client *AliPayClient) {
+func (a *Client) SetCharset(charset string) (client *Client) {
 	a.mu.Lock()
-	if charset == null {
+	if charset == gopay.NULL {
 		a.Charset = "utf-8"
 	} else {
 		a.Charset = charset
@@ -132,9 +134,9 @@ func (a *AliPayClient) SetCharset(charset string) (client *AliPayClient) {
 }
 
 // 设置签名算法类型,目前支持RSA2和RSA,默认推荐使用 RSA2
-func (a *AliPayClient) SetSignType(signType string) (client *AliPayClient) {
+func (a *Client) SetSignType(signType string) (client *Client) {
 	a.mu.Lock()
-	if signType == null {
+	if signType == gopay.NULL {
 		a.SignType = "RSA2"
 	} else {
 		a.SignType = signType
@@ -144,7 +146,7 @@ func (a *AliPayClient) SetSignType(signType string) (client *AliPayClient) {
 }
 
 // 设置应用授权
-func (a *AliPayClient) SetAppAuthToken(appAuthToken string) (client *AliPayClient) {
+func (a *Client) SetAppAuthToken(appAuthToken string) (client *Client) {
 	a.mu.Lock()
 	a.AppAuthToken = appAuthToken
 	a.mu.Unlock()
@@ -152,7 +154,7 @@ func (a *AliPayClient) SetAppAuthToken(appAuthToken string) (client *AliPayClien
 }
 
 // 设置用户信息授权
-func (a *AliPayClient) SetAuthToken(authToken string) (client *AliPayClient) {
+func (a *Client) SetAuthToken(authToken string) (client *Client) {
 	a.mu.Lock()
 	a.AuthToken = authToken
 	a.mu.Unlock()
@@ -160,7 +162,7 @@ func (a *AliPayClient) SetAuthToken(authToken string) (client *AliPayClient) {
 }
 
 // 获取参数签名
-func getRsaSign(bm BodyMap, signType, privateKey string) (sign string, err error) {
+func getRsaSign(bm gopay.BodyMap, signType, privateKey string) (sign string, err error) {
 	var (
 		block          *pem.Block
 		h              hash.Hash
@@ -170,7 +172,7 @@ func getRsaSign(bm BodyMap, signType, privateKey string) (sign string, err error
 	)
 
 	if block, _ = pem.Decode([]byte(privateKey)); block == nil {
-		return null, errors.New("pem.Decode:privateKey decode error")
+		return gopay.NULL, errors.New("pem.Decode:privateKey decode error")
 	}
 	if key, err = x509.ParsePKCS1PrivateKey(block.Bytes); err != nil {
 		return
@@ -197,7 +199,7 @@ func getRsaSign(bm BodyMap, signType, privateKey string) (sign string, err error
 }
 
 // 格式化请求URL参数
-func FormatAliPayURLParam(body BodyMap) (urlParam string) {
+func FormatURLParam(body gopay.BodyMap) (urlParam string) {
 	v := url.Values{}
 	for key, value := range body {
 		v.Add(key, value.(string))

+ 30 - 28
alipay_service_api.go → alipay/alipay_service_api.go

@@ -1,4 +1,4 @@
-package gopay
+package alipay
 
 import (
 	"crypto"
@@ -19,6 +19,8 @@ import (
 	"reflect"
 	"strings"
 	"time"
+
+	"github.com/iGoogle-ink/gopay"
 )
 
 // 允许进行 sn 提取的证书签名算法
@@ -39,12 +41,12 @@ var allowSignatureAlgorithm = map[string]bool{
 //    返回参数bm:Notify请求的参数
 //    返回参数err:错误信息
 //    文档:https://docs.open.alipay.com/203/105286/
-func ParseAliPayNotifyResultToBodyMap(req *http.Request) (bm BodyMap, err error) {
+func ParseNotifyResultToBodyMap(req *http.Request) (bm gopay.BodyMap, err error) {
 	if err = req.ParseForm(); err != nil {
 		return nil, err
 	}
 	var form map[string][]string = req.Form
-	bm = make(BodyMap, len(form))
+	bm = make(gopay.BodyMap, len(form))
 	for k, v := range form {
 		if len(v) == 1 {
 			bm.Set(k, v[0])
@@ -58,7 +60,7 @@ func ParseAliPayNotifyResultToBodyMap(req *http.Request) (bm BodyMap, err error)
 //    返回参数notifyReq:Notify请求的参数
 //    返回参数err:错误信息
 //    文档:https://docs.open.alipay.com/203/105286/
-func ParseAliPayNotifyResult(req *http.Request) (notifyReq *AliPayNotifyRequest, err error) {
+func ParseNotifyResult(req *http.Request) (notifyReq *AliPayNotifyRequest, err error) {
 	notifyReq = new(AliPayNotifyRequest)
 	if err = req.ParseForm(); err != nil {
 		return
@@ -95,7 +97,7 @@ func ParseAliPayNotifyResult(req *http.Request) (notifyReq *AliPayNotifyRequest,
 	notifyReq.PassbackParams = req.Form.Get("passback_params")
 
 	billList := req.Form.Get("fund_bill_list")
-	if billList != null {
+	if billList != gopay.NULL {
 		bills := make([]*fundBillListInfo, 0)
 		if err = json.Unmarshal([]byte(billList), &bills); err != nil {
 			return nil, fmt.Errorf(`"fund_bill_list" xml.Unmarshal:%s`, err.Error())
@@ -106,7 +108,7 @@ func ParseAliPayNotifyResult(req *http.Request) (notifyReq *AliPayNotifyRequest,
 	}
 
 	detailList := req.Form.Get("voucher_detail_list")
-	if detailList != null {
+	if detailList != gopay.NULL {
 		details := make([]*voucherDetailListInfo, 0)
 		if err = json.Unmarshal([]byte(detailList), &details); err != nil {
 			return nil, fmt.Errorf(`"voucher_detail_list" xml.Unmarshal:%s`, err.Error())
@@ -134,7 +136,7 @@ A:开发者上传自己的应用公钥证书后,开放平台会为开发者
 基于该机制可实现支付宝公钥证书变更时开发者无感知,当前开放平台提供的SDK已基于该机制实现对应功能。若开发者未通过SDK接入,须自行实现该功能。
 */
 
-// VerifyAliPaySyncSign 支付宝同步返回验签
+// VerifySyncSign 支付宝同步返回验签
 //    注意:APP支付,手机网站支付,电脑网站支付 暂不支持同步返回验签
 //    aliPayPublicKey:支付宝公钥
 //    signData:待验签参数,aliRsp.SignData
@@ -142,24 +144,24 @@ A:开发者上传自己的应用公钥证书后,开放平台会为开发者
 //    返回参数ok:是否验签通过
 //    返回参数err:错误信息
 //    验签文档:https://docs.open.alipay.com/200/106120
-func VerifyAliPaySyncSign(aliPayPublicKey, signData, sign string) (ok bool, err error) {
+func VerifySyncSign(aliPayPublicKey, signData, sign string) (ok bool, err error) {
 
 	// 支付宝公钥验签
-	pKey := FormatAliPayPublicKey(aliPayPublicKey)
+	pKey := FormatPublicKey(aliPayPublicKey)
 	if err = verifyAliPaySign(signData, sign, "RSA2", pKey); err != nil {
 		return false, err
 	}
 	return true, nil
 }
 
-// VerifyAliPaySign 支付宝异步通知验签
+// VerifySign 支付宝异步通知验签
 //    注意:APP支付,手机网站支付,电脑网站支付 暂不支持同步返回验签
 //    aliPayPublicKey:支付宝公钥
 //    bean:此参数为异步通知解析的结构体或BodyMap:notifyReq 或 bm
 //    返回参数ok:是否验签通过
 //    返回参数err:错误信息
 //    验签文档:https://docs.open.alipay.com/200/106120
-func VerifyAliPaySign(aliPayPublicKey string, bean interface{}) (ok bool, err error) {
+func VerifySign(aliPayPublicKey string, bean interface{}) (ok bool, err error) {
 	if bean == nil {
 		return false, errors.New("bean is nil")
 	}
@@ -167,10 +169,10 @@ func VerifyAliPaySign(aliPayPublicKey string, bean interface{}) (ok bool, err er
 		bodySign     string
 		bodySignType string
 		signData     string
-		bm           = make(BodyMap)
+		bm           = make(gopay.BodyMap)
 	)
 	if reflect.ValueOf(bean).Kind() == reflect.Map {
-		if bm, ok = bean.(BodyMap); ok {
+		if bm, ok = bean.(gopay.BodyMap); ok {
 			bodySign = bm.Get("sign")
 			bodySignType = bm.Get("sign_type")
 			bm.Remove("sign")
@@ -191,7 +193,7 @@ func VerifyAliPaySign(aliPayPublicKey string, bean interface{}) (ok bool, err er
 		bm.Remove("sign_type")
 		signData = bm.EncodeAliPaySignParams()
 	}
-	pKey := FormatAliPayPublicKey(aliPayPublicKey)
+	pKey := FormatPublicKey(aliPayPublicKey)
 	if err = verifyAliPaySign(signData, bodySign, bodySignType, pKey); err != nil {
 		return false, err
 	}
@@ -258,8 +260,8 @@ func FormatPrivateKey(privateKey string) (pKey string) {
 	return
 }
 
-// FormatAliPayPublicKey 格式化 普通支付宝公钥
-func FormatAliPayPublicKey(publicKey string) (pKey string) {
+// FormatPublicKey 格式化 普通支付宝公钥
+func FormatPublicKey(publicKey string) (pKey string) {
 	var buffer strings.Builder
 	buffer.WriteString("-----BEGIN PUBLIC KEY-----\n")
 	rawLen := 64
@@ -364,7 +366,7 @@ func DecryptAliPayOpenDataToStruct(encryptedData, secretKey string, beanPtr inte
 	originData = make([]byte, len(secretData))
 	blockMode.CryptBlocks(originData, secretData)
 	if len(originData) > 0 {
-		originData = PKCS5UnPadding(originData)
+		originData = gopay.PKCS5UnPadding(originData)
 	}
 	if err = json.Unmarshal(originData, beanPtr); err != nil {
 		return fmt.Errorf("json.Unmarshal:%s", err.Error())
@@ -377,7 +379,7 @@ func DecryptAliPayOpenDataToStruct(encryptedData, secretKey string, beanPtr inte
 //    secretKey:AES密钥,支付宝管理平台配置
 //    文档:https://docs.alipay.com/mini/introduce/aes
 //    文档:https://docs.open.alipay.com/common/104567
-func DecryptAliPayOpenDataToBodyMap(encryptedData, secretKey string) (bm BodyMap, err error) {
+func DecryptAliPayOpenDataToBodyMap(encryptedData, secretKey string) (bm gopay.BodyMap, err error) {
 	var (
 		aesKey, originData []byte
 		ivKey              = []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
@@ -396,16 +398,16 @@ func DecryptAliPayOpenDataToBodyMap(encryptedData, secretKey string) (bm BodyMap
 	originData = make([]byte, len(secretData))
 	blockMode.CryptBlocks(originData, secretData)
 	if len(originData) > 0 {
-		originData = PKCS5UnPadding(originData)
+		originData = gopay.PKCS5UnPadding(originData)
 	}
-	bm = make(BodyMap)
+	bm = make(gopay.BodyMap)
 	if err = json.Unmarshal(originData, &bm); err != nil {
 		return nil, fmt.Errorf("json.Unmarshal:%s", err.Error())
 	}
 	return
 }
 
-// AliPaySystemOauthToken 换取授权访问令牌(默认使用utf-8,RSA2)
+// SystemOauthToken 换取授权访问令牌(默认使用utf-8,RSA2)
 //    appId:应用ID
 //    PrivateKey:应用私钥
 //    grantType:值为 authorization_code 时,代表用code换取;值为 refresh_token 时,代表用refresh_token换取,传空默认code换取
@@ -413,7 +415,7 @@ func DecryptAliPayOpenDataToBodyMap(encryptedData, secretKey string) (bm BodyMap
 //    文档:https://docs.open.alipay.com/api_9/alipay.system.oauth.token
 func AliPaySystemOauthToken(appId, privateKey, grantType, codeOrToken string) (rsp *AliPaySystemOauthTokenResponse, err error) {
 	var bs []byte
-	bm := make(BodyMap)
+	bm := make(gopay.BodyMap)
 	if "authorization_code" == grantType {
 		bm.Set("grant_type", "authorization_code")
 		bm.Set("code", codeOrToken)
@@ -424,7 +426,7 @@ func AliPaySystemOauthToken(appId, privateKey, grantType, codeOrToken string) (r
 		bm.Set("grant_type", "authorization_code")
 		bm.Set("code", codeOrToken)
 	}
-	if bs, err = aliPaySystemOauthToken(appId, privateKey, bm, "alipay.system.oauth.token", true); err != nil {
+	if bs, err = systemOauthToken(appId, privateKey, bm, "alipay.system.oauth.token", true); err != nil {
 		return
 	}
 	rsp = new(AliPaySystemOauthTokenResponse)
@@ -432,19 +434,19 @@ func AliPaySystemOauthToken(appId, privateKey, grantType, codeOrToken string) (r
 		return nil, fmt.Errorf("json.Unmarshal:%s", err.Error())
 	}
 	if rsp.Response.AccessToken == "" {
-		return nil, errors.New("access_token is null")
+		return nil, errors.New("access_token is NULL")
 	}
 	return
 }
 
-// aliPaySystemOauthToken 向支付宝发送请求
-func aliPaySystemOauthToken(appId, privateKey string, body BodyMap, method string, isProd bool) (bs []byte, err error) {
+// systemOauthToken 向支付宝发送请求
+func systemOauthToken(appId, privateKey string, body gopay.BodyMap, method string, isProd bool) (bs []byte, err error) {
 	body.Set("app_id", appId)
 	body.Set("method", method)
 	body.Set("format", "JSON")
 	body.Set("charset", "utf-8")
 	body.Set("sign_type", "RSA2")
-	body.Set("timestamp", time.Now().Format(TimeLayout))
+	body.Set("timestamp", time.Now().Format(gopay.TimeLayout))
 	body.Set("version", "1.0")
 	var (
 		sign string
@@ -458,7 +460,7 @@ func aliPaySystemOauthToken(appId, privateKey string, body BodyMap, method strin
 	if !isProd {
 		url = zfbSandboxBaseUrlUtf8
 	}
-	_, bs, errs := NewHttpClient().Type(TypeForm).Post(url).SendString(FormatAliPayURLParam(body)).EndBytes()
+	_, bs, errs := gopay.NewHttpClient().Type(gopay.TypeForm).Post(url).SendString(FormatURLParam(body)).EndBytes()
 	if len(errs) > 0 {
 		return nil, errs[0]
 	}

+ 21 - 16
body_map.go

@@ -18,7 +18,7 @@ func (bm BodyMap) Set(key string, value interface{}) {
 // 获取参数
 func (bm BodyMap) Get(key string) string {
 	if bm == nil {
-		return null
+		return NULL
 	}
 	var (
 		value interface{}
@@ -26,7 +26,7 @@ func (bm BodyMap) Get(key string) string {
 		v     string
 	)
 	if value, ok = bm[key]; !ok {
-		return null
+		return NULL
 	}
 	if v, ok = value.(string); ok {
 		return v
@@ -36,14 +36,14 @@ func (bm BodyMap) Get(key string) string {
 
 func convertToString(v interface{}) (str string) {
 	if v == nil {
-		return null
+		return NULL
 	}
 	var (
 		bs  []byte
 		err error
 	)
 	if bs, err = json.Marshal(v); err != nil {
-		return null
+		return NULL
 	}
 	str = string(bs)
 	return
@@ -54,22 +54,27 @@ func (bm BodyMap) Remove(key string) {
 	delete(bm, key)
 }
 
-type xmlMapEntry struct {
+type xmlMapMarshal struct {
 	XMLName xml.Name
 	Value   interface{} `xml:",cdata"`
 }
 
+type xmlMapUnmarshal struct {
+	XMLName xml.Name
+	Value   string `xml:",cdata"`
+}
+
 func (bm BodyMap) MarshalXML(e *xml.Encoder, start xml.StartElement) (err error) {
 	if len(bm) == 0 {
 		return nil
 	}
-	start.Name = xml.Name{null, "xml"}
+	start.Name = xml.Name{NULL, "xml"}
 	if err = e.EncodeToken(start); err != nil {
 		return
 	}
 	for k := range bm {
-		if v := bm.Get(k); v != null {
-			e.Encode(xmlMapEntry{XMLName: xml.Name{Local: k}, Value: v})
+		if v := bm.Get(k); v != NULL {
+			e.Encode(xmlMapMarshal{XMLName: xml.Name{Local: k}, Value: v})
 		}
 	}
 	return e.EncodeToken(start.End())
@@ -77,16 +82,16 @@ func (bm BodyMap) MarshalXML(e *xml.Encoder, start xml.StartElement) (err error)
 
 func (bm *BodyMap) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error) {
 	for {
-		var e xmlMapEntry
+		var e xmlMapUnmarshal
 		err = d.Decode(&e)
-		if err == io.EOF {
-			break
-		} else if err != nil {
-			return
+		if err != nil {
+			if err == io.EOF {
+				return nil
+			}
+			return err
 		}
 		bm.Set(e.XMLName.Local, e.Value)
 	}
-	return
 }
 
 // ("bar=baz&foo=quux") sorted by key.
@@ -100,7 +105,7 @@ func (bm BodyMap) EncodeWeChatSignParams(apiKey string) string {
 	}
 	sort.Strings(keyList)
 	for _, k := range keyList {
-		if v := bm.Get(k); v != null {
+		if v := bm.Get(k); v != NULL {
 			buf.WriteString(k)
 			buf.WriteByte('=')
 			buf.WriteString(v)
@@ -125,7 +130,7 @@ func (bm BodyMap) EncodeAliPaySignParams() string {
 	}
 	sort.Strings(keyList)
 	for _, k := range keyList {
-		if v := bm.Get(k); v != null {
+		if v := bm.Get(k); v != NULL {
 			buf.WriteString(k)
 			buf.WriteByte('=')
 			buf.WriteString(v)

+ 1 - 68
constant.go

@@ -1,75 +1,8 @@
 package gopay
 
 const (
-	null       string = ""
+	NULL       string = ""
 	TimeLayout string = "2006-01-02 15:04:05"
 	DateLayout string = "2006-01-02"
 	Version    string = "1.4.6"
-	// 微信
-	// ===========================================================================================
-
-	// 境外国家地区
-	China         Country = 1 // 中国国内
-	China2        Country = 2 // 中国国内(冗灾方案)
-	SoutheastAsia Country = 3 // 东南亚
-	Other         Country = 4 // 其他国家
-
-	// URL
-	wxBaseUrlCh  = "https://api.mch.weixin.qq.com/"   //中国国内
-	wxBaseUrlCh2 = "https://api2.mch.weixin.qq.com/"  //中国国内
-	wxBaseUrlHk  = "https://apihk.mch.weixin.qq.com/" //东南亚
-	wxBaseUrlUs  = "https://apius.mch.weixin.qq.com/" //其他
-
-	// 正式
-	wxMicropay          = "pay/micropay"                          //提交付款码支付
-	wxUnifiedorder      = "pay/unifiedorder"                      //统一下单
-	wxOrderquery        = "pay/orderquery"                        //查询订单
-	wxCloseorder        = "pay/closeorder"                        //关闭订单
-	wxRefund            = "secapi/pay/refund"                     //申请退款
-	wxReverse           = "secapi/pay/reverse"                    //撤销订单
-	wxRefundquery       = "pay/refundquery"                       //查询退款
-	wxDownloadbill      = "pay/downloadbill"                      //下载对账单
-	wxDownloadfundflow  = "pay/downloadfundflow"                  //下载资金账单
-	wxBatchquerycomment = "billcommentsp/batchquerycomment"       //拉取订单评价数据
-	wxTransfers         = "mmpaymkttransfers/promotion/transfers" //企业向微信用户个人付款
-	wxEntrustPublic     = "papay/entrustweb"                      //公众号纯签约
-	wxEntrustApp        = "papay/preentrustweb"                   //APP纯签约
-	wxEntrustH5         = "papay/h5entrustweb"                    //H5纯签约
-	wxEntrustQuery      = "papay/querycontract"                   //查询签约关系
-	wxEntrustDelete     = "papay/deletecontract"                  //申请解约
-	wxEntrustApplyPay   = "pay/pappayapply"                       //申请扣款
-	wxEntrustQueryOrder = "pay/paporderquery"                     //查询扣款订单
-
-	// SanBox
-	wxSandboxGetsignkey        = "https://api.mch.weixin.qq.com/sandboxnew/pay/getsignkey"
-	wxSandboxMicropay          = "sandboxnew/pay/micropay"
-	wxSandboxUnifiedorder      = "sandboxnew/pay/unifiedorder"
-	wxSandboxOrderquery        = "sandboxnew/pay/orderquery"
-	wxSandboxCloseorder        = "sandboxnew/pay/closeorder"
-	wxSandboxRefund            = "sandboxnew/pay/refund"
-	wxSandboxReverse           = "sandboxnew/pay/reverse"
-	wxSandboxRefundquery       = "sandboxnew/pay/refundquery"
-	wxSandboxDownloadbill      = "sandboxnew/pay/downloadbill"
-	wxSandboxDownloadfundflow  = "sandboxnew/pay/downloadfundflow"
-	wxSandboxBatchquerycomment = "sandboxnew/billcommentsp/batchquerycomment"
-
-	// 支付类型
-	TradeType_Mini   = "JSAPI"
-	TradeType_JsApi  = "JSAPI"
-	TradeType_App    = "APP"
-	TradeType_H5     = "MWEB"
-	TradeType_Native = "NATIVE"
-
-	// 签名方式
-	SignType_MD5         = "MD5"
-	SignType_HMAC_SHA256 = "HMAC-SHA256"
-
-	// 支付宝
-	// ==========================================================================================
-
-	// URL
-	zfbBaseUrl            = "https://openapi.alipay.com/gateway.do"
-	zfbSandboxBaseUrl     = "https://openapi.alipaydev.com/gateway.do"
-	zfbBaseUrlUtf8        = "https://openapi.alipay.com/gateway.do?charset=utf-8"
-	zfbSandboxBaseUrlUtf8 = "https://openapi.alipaydev.com/gateway.do?charset=utf-8"
 )

+ 3 - 3
doc.go

@@ -4,7 +4,7 @@ package gopay
 
 // Java SDK 获取Root证书SN
 public static String getRootCertSN(String rootCertContent){
-   String rootCertSN = null;
+   String rootCertSN = NULL;
    try {
 	   X509Certificate[] x509Certificates = readPemCertChain(rootCertContent);
 	   MessageDigest md = MessageDigest.getInstance("MD5");
@@ -29,7 +29,7 @@ public static String getRootCertSN(String rootCertContent){
 
 // Java SDK 获取证书
 private X509Certificate getCert(String  certPath) throws AlipayApiException{
-	InputStream inputStream = null;
+	InputStream inputStream = NULL;
 	try {
 		inputStream = new FileInputStream(certPath);
 		CertificateFactory cf = CertificateFactory.getInstance("X.509");
@@ -42,7 +42,7 @@ private X509Certificate getCert(String  certPath) throws AlipayApiException{
 		throw new AlipayApiException(e);
 	}finally {
 		try {
-			if (inputStream != null) {
+			if (inputStream != NULL) {
 				inputStream.close();
 			}
 		}catch (IOException e) {

+ 5 - 4
examples/alipay/alipay_AliPaySystemOauthToken.go

@@ -4,15 +4,16 @@ import (
 	"fmt"
 
 	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/alipay"
 )
 
-func AliPaySystemOauthToken() {
+func SystemOauthToken() {
 	privateKey := "MIIEogIBAAKCAQEAy+CRzKw4krA2RzCDTqg5KJg92XkOY0RN3pW4sYInPqnGtHV7YDHu5nMuxY6un+dLfo91OFOEg+RI+WTOPoM4xJtsOaJwQ1lpjycoeLq1OyetGW5Q8wO+iLWJASaMQM/t/aXR/JHaguycJyqlHSlxANvKKs/tOHx9AhW3LqumaCwz71CDF/+70scYuZG/7wxSjmrbRBswxd1Sz9KHdcdjqT8pmieyPqnM24EKBexHDmQ0ySXvLJJy6eu1dJsPIz+ivX6HEfDXmSmJ71AZVqZyCI1MhK813R5E7XCv5NOtskTe3y8uiIhgGpZSdB77DOyPLcmVayzFVLAQ3AOBDmsY6wIDAQABAoIBAHjsNq31zAw9FcR9orQJlPVd7vlJEt6Pybvmg8hNESfanO+16rpwg2kOEkS8zxgqoJ1tSzJgXu23fgzl3Go5fHcoVDWPAhUAOFre9+M7onh2nPXDd6Hbq6v8OEmFapSaf2b9biHnBHq5Chk08v/r74l501w3PVVOiPqulJrK1oVb+0/YmCvVFpGatBcNaefKUEcA+vekWPL7Yl46k6XeUvRfTwomCD6jpYLUhsAKqZiQJhMGoaLglZvkokQMF/4G78K7FbbVLMM1+JDh8zJ/DDVdY2vHREUcCGhl4mCVQtkzIbpxG++vFg7/g/fDI+PquG22hFILTDdtt2g2fV/4wmkCgYEA6goRQYSiM03y8Tt/M4u1Mm7OWYCksqAsU7rzQllHekIN3WjD41Xrjv6uklsX3sTG1syo7Jr9PGE1xQgjDEIyO8h/3lDQyLyycYnyUPGNNMX8ZjmGwcM51DQ/QfIrY/CXjnnW+MVpmNclAva3L33KXCWjw20VsROV1EA8LCL94BUCgYEA3wH4ANpzo7NqXf+2WlPPMuyRrF0QPIRGlFBNtaKFy0mvoclkREPmK7+N4NIGtMf5JNODS5HkFRgmU4YNdupA2I8lIYpD+TsIobZxGUKUkYzRZYZ1m1ttL69YYvCVz9Xosw/VoQ+RrW0scS5yUKqFMIUOV2R/Imi//c5TdKx6VP8CgYAnJ1ADugC4vI2sNdvt7618pnT3HEJxb8J6r4gKzYzbszlGlURQQAuMfKcP7RVtO1ZYkRyhmLxM4aZxNA9I+boVrlFWDAchzg+8VuunBwIslgLHx0/4EoUWLzd1/OGtco6oU1HXhI9J9pRGjqfO1iiIifN/ujwqx7AFNknayG/YkQKBgD6yNgA/ak12rovYzXKdp14Axn+39k2dPp6J6R8MnyLlB3yruwW6NSbNhtzTD1GZ+wCQepQvYvlPPc8zm+t3tl1r+Rtx3ORf5XBZc3iPkGdPOLubTssrrAnA+U9vph61W+OjqwLJ9sHUNK9pSHhHSIS4k6ycM2YAHyIC9NGTgB0PAoGAJjwd1DgMaQldtWnuXjvohPOo8cQudxXYcs6zVRbx6vtjKe2v7e+eK1SSVrR5qFV9AqxDfGwq8THenRa0LC3vNNplqostuehLhkWCKE7Y75vXMR7N6KU1kdoVWgN4BhXSwuRxmHMQfSY7q3HG3rDGz7mzXo1FVMr/uE4iDGm0IXY="
 	//初始化支付宝客户端
 	//    appId:应用ID
 	//    privateKey:应用秘钥
 	//    isProd:是否是正式环境
-	client := gopay.NewAliPayClient("2016091200494382", privateKey, false)
+	client := alipay.NewClient("2016091200494382", privateKey, false)
 	//配置公共参数
 	client.SetCharset("utf-8").
 		SetSignType("RSA2").
@@ -23,7 +24,7 @@ func AliPaySystemOauthToken() {
 	body.Set("code", "3a06216ac8f84b8c93507bb9774bWX11")
 
 	//发起请求
-	aliRsp, err := client.AliPaySystemOauthToken(body)
+	aliRsp, err := client.SystemOauthToken(body)
 	if err != nil {
 		fmt.Println("err:", err)
 		return
@@ -39,7 +40,7 @@ func AliPaySystemOauthToken() {
 	body2.Set("out_trade_no", "GZ201901301040355708")
 	body2.Set("total_amount", "0.01")
 
-	rsp, err := client.AliPayTradeCreate(body2)
+	rsp, err := client.TradeCreate(body2)
 	if err != nil {
 		fmt.Println("err:", err)
 		return

+ 2 - 1
examples/alipay/alipay_AliPayTradeAppPay.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 
 	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/alipay"
 )
 
 func AliPayTradeAppPay() {
@@ -13,7 +14,7 @@ func AliPayTradeAppPay() {
 	//    appId:应用ID
 	//    privateKey:应用秘钥
 	//    isProd:是否是正式环境
-	client := gopay.NewAliPayClient("2016091200494382", privateKey, false)
+	client := alipay.NewClient("2016091200494382", privateKey, false)
 	//配置公共参数
 	client.SetCharset("utf-8").
 		SetSignType("RSA2").

+ 2 - 1
examples/alipay/alipay_AliPayTradeCancel.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 
 	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/alipay"
 )
 
 func AliPayTradeCancel() {
@@ -13,7 +14,7 @@ func AliPayTradeCancel() {
 	//    appId:应用ID
 	//    privateKey:应用秘钥
 	//    isProd:是否是正式环境
-	client := gopay.NewAliPayClient("2016091200494382", privateKey, false)
+	client := alipay.NewClient("2016091200494382", privateKey, false)
 	//配置公共参数
 	client.SetCharset("utf-8").
 		SetSignType("RSA2").

+ 2 - 1
examples/alipay/alipay_AliPayTradeClose.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 
 	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/alipay"
 )
 
 func AliPayTradeClose() {
@@ -13,7 +14,7 @@ func AliPayTradeClose() {
 	//    appId:应用ID
 	//    privateKey:应用秘钥
 	//    isProd:是否是正式环境
-	client := gopay.NewAliPayClient("2016091200494382", privateKey, false)
+	client := alipay.NewClient("2016091200494382", privateKey, false)
 	//配置公共参数
 	client.SetCharset("utf-8").
 		SetSignType("RSA2").

+ 4 - 3
examples/alipay/alipay_AliPayTradeCreate.go

@@ -4,9 +4,10 @@ import (
 	"fmt"
 
 	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/alipay"
 )
 
-func AliPayTradeCreate() {
+func TradeCreate() {
 	//aliPayPublicKey := "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1wn1sU/8Q0rYLlZ6sq3enrPZw2ptp6FecHR2bBFLjJ+sKzepROd0bKddgj+Mr1ffr3Ej78mLdWV8IzLfpXUi945DkrQcOUWLY0MHhYVG2jSs/qzFfpzmtut2Cl2TozYpE84zom9ei06u2AXLMBkU6VpznZl+R4qIgnUfByt3Ix5b3h4Cl6gzXMAB1hJrrrCkq+WvWb3Fy0vmk/DUbJEz8i8mQPff2gsHBE1nMPvHVAMw1GMk9ImB4PxucVek4ZbUzVqxZXphaAgUXFK2FSFU+Q+q1SPvHbUsjtIyL+cLA6H/6ybFF9Ffp27Y14AHPw29+243/SpMisbGcj2KD+evBwIDAQAB"
 	//privateKey := "MIIEpgIBAAKCAQEA5JwIRwps/xrBFLCRHL727tofHEDE74I+NMkUkHCEd0qI7lOYrz72761hjw0/Np+io8DQDNf3AV0+HJGQAuMadhgmcLUnfB7BJwEL1wgc2Uk8oj8XBIJUKmc+APtJ3NhUgd7s4p63IVKjQfp8oMbGZS3/dJdamBEqGJn3bep7WlKyJy5bL3KY+fX5F1DNif8xfHBSygkniKhTt/pkKaEP6uiEvhZuorPKGTowU99cqJZAqNVGcZV/30UEerR9BHV5g3iZHRxebGNbC9WSBqVWoGhdo23Xl0QG6KmuZ1akF7mdq1e7Qlpm0SkYimqipRhSflu2N/mIW2pesypX2DRE8wIDAQABAoIBAQDDvkJsKaYoTI00nPaziWPAIm3u8BpwBbIj2mTMRDt4NQ7IGjYrH5uqn2dgaHRO3iMRWYAK70RlG6SaK50Gi9RVd9o6OTKk2WSDdCbiKOUiu826EpEv4DQW1q3Fg2S8P1MknG9yn3mog6ycStE5jNnFOrx35TzB5jiINhUhPVv/eh6iDkHCxfOh2R4+vPYjNXlzhgcR3qh19Rnd2uuzscbRtljoZpA3qE0tIawW7HmesKqjfHL3O/kHJGmZjK/uhNvZmPMzilmFb+q3R3BXbAPNc/efkv0GF1fS0Xy2h0YYfkNTDzewsU7Qwkw/iT29IUUn9uxAux6SYyubCdLRIMtpAoGBAP3uxgt0kX4AN0CUibkyvDlaw+amkjTgk9voH78CPUej58sIkWcaPJJwAFOhzNbsTlNp3mZ2xx58gqJU2Rm1/6bsQbYRjN9qVY8Fco7ClysOaf9bwDBqnIjv9eHZdw8EmR4qnPCH9yjBWDMODKxIhAhsuwm4D7GmsHrFAp5w7PlnAoGBAOZ4e2sOfVAiM9ZoHIlaNLW2Z1PKkc/1k+Hxoxl5dq9nHB9RAGqpO4vjbMc6d1wVRr02GZE8RaLSzS7WrAgSzsWgtql4P8TvrjPvIPEyN1B7/eqR6yNDGRHLkYbDg54SeRI/yUg7EwMARJqa24zP503IA40JZgaVHLti5XYCIoSVAoGBAIx/oXpTG/EQY4HK7czXgodlbgDfZwP0wjqpW29O6OMLkEOpUPIv9RW8/KFJY9IC22+RoykkTRXUJF92/MwaBAKys8TuPviamA5TIEhW6Fc9WW6dsF/ZjRTDWFOHBDX+AE5Nm5oGUL1vBMLy4hYs5UjYCEDfY2eS6BB1kvZhWuy/AoGBAKJHf4+YOkBsdNepoz5LmAXDE+p6HkWyA5j6jf9n+Vv0XGbooER6OQV886Es19Ks4IxmRYZwTBAkInmyipt8sr+RNE0L8Mr4gU7sN+Pdmfk/9UBv0oOXwVU4Y5XioRByrXFeHJqRjgd07tl15NW3poSsK2PplD9aS0rejfeT9T4pAoGBAKELHKfRAWILgkI/L5RrvaoUEkdy1hw9a+b+V1TKB+wDbrsomzL2BPnBYjqtw2ZhTffpxzS3ZpSzlMtgmcYhpyAvq5GlPw+wbsNXr4tCIu8eYLc6QoypmO8kE2FornyZfol5ygEu6HSUSwEHHjIQBDxtAlYgBPZOetDVdDVJD1nR"
 	privateKey := "MIIEogIBAAKCAQEAy+CRzKw4krA2RzCDTqg5KJg92XkOY0RN3pW4sYInPqnGtHV7YDHu5nMuxY6un+dLfo91OFOEg+RI+WTOPoM4xJtsOaJwQ1lpjycoeLq1OyetGW5Q8wO+iLWJASaMQM/t/aXR/JHaguycJyqlHSlxANvKKs/tOHx9AhW3LqumaCwz71CDF/+70scYuZG/7wxSjmrbRBswxd1Sz9KHdcdjqT8pmieyPqnM24EKBexHDmQ0ySXvLJJy6eu1dJsPIz+ivX6HEfDXmSmJ71AZVqZyCI1MhK813R5E7XCv5NOtskTe3y8uiIhgGpZSdB77DOyPLcmVayzFVLAQ3AOBDmsY6wIDAQABAoIBAHjsNq31zAw9FcR9orQJlPVd7vlJEt6Pybvmg8hNESfanO+16rpwg2kOEkS8zxgqoJ1tSzJgXu23fgzl3Go5fHcoVDWPAhUAOFre9+M7onh2nPXDd6Hbq6v8OEmFapSaf2b9biHnBHq5Chk08v/r74l501w3PVVOiPqulJrK1oVb+0/YmCvVFpGatBcNaefKUEcA+vekWPL7Yl46k6XeUvRfTwomCD6jpYLUhsAKqZiQJhMGoaLglZvkokQMF/4G78K7FbbVLMM1+JDh8zJ/DDVdY2vHREUcCGhl4mCVQtkzIbpxG++vFg7/g/fDI+PquG22hFILTDdtt2g2fV/4wmkCgYEA6goRQYSiM03y8Tt/M4u1Mm7OWYCksqAsU7rzQllHekIN3WjD41Xrjv6uklsX3sTG1syo7Jr9PGE1xQgjDEIyO8h/3lDQyLyycYnyUPGNNMX8ZjmGwcM51DQ/QfIrY/CXjnnW+MVpmNclAva3L33KXCWjw20VsROV1EA8LCL94BUCgYEA3wH4ANpzo7NqXf+2WlPPMuyRrF0QPIRGlFBNtaKFy0mvoclkREPmK7+N4NIGtMf5JNODS5HkFRgmU4YNdupA2I8lIYpD+TsIobZxGUKUkYzRZYZ1m1ttL69YYvCVz9Xosw/VoQ+RrW0scS5yUKqFMIUOV2R/Imi//c5TdKx6VP8CgYAnJ1ADugC4vI2sNdvt7618pnT3HEJxb8J6r4gKzYzbszlGlURQQAuMfKcP7RVtO1ZYkRyhmLxM4aZxNA9I+boVrlFWDAchzg+8VuunBwIslgLHx0/4EoUWLzd1/OGtco6oU1HXhI9J9pRGjqfO1iiIifN/ujwqx7AFNknayG/YkQKBgD6yNgA/ak12rovYzXKdp14Axn+39k2dPp6J6R8MnyLlB3yruwW6NSbNhtzTD1GZ+wCQepQvYvlPPc8zm+t3tl1r+Rtx3ORf5XBZc3iPkGdPOLubTssrrAnA+U9vph61W+OjqwLJ9sHUNK9pSHhHSIS4k6ycM2YAHyIC9NGTgB0PAoGAJjwd1DgMaQldtWnuXjvohPOo8cQudxXYcs6zVRbx6vtjKe2v7e+eK1SSVrR5qFV9AqxDfGwq8THenRa0LC3vNNplqostuehLhkWCKE7Y75vXMR7N6KU1kdoVWgN4BhXSwuRxmHMQfSY7q3HG3rDGz7mzXo1FVMr/uE4iDGm0IXY="
@@ -14,7 +15,7 @@ func AliPayTradeCreate() {
 	//    appId:应用ID
 	//    privateKey:应用秘钥
 	//    isProd:是否是正式环境
-	client := gopay.NewAliPayClient("2016091200494382", privateKey, false)
+	client := alipay.NewClient("2016091200494382", privateKey, false)
 	//配置公共参数
 	client.SetCharset("utf-8").
 		SetSignType("RSA2").
@@ -26,7 +27,7 @@ func AliPayTradeCreate() {
 	body.Set("out_trade_no", "GZ201901301040355709")
 	body.Set("total_amount", "0.01")
 	//创建订单
-	aliRsp, err := client.AliPayTradeCreate(body)
+	aliRsp, err := client.TradeCreate(body)
 	if err != nil {
 		fmt.Println("err:", err)
 		return

+ 4 - 3
examples/alipay/alipay_AliPayTradeFastPayRefundQuery.go

@@ -4,16 +4,17 @@ import (
 	"fmt"
 
 	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/alipay"
 )
 
-func AliPayTradeFastPayRefundQuery() {
+func TradeFastPayRefundQuery() {
 	//aliPayPublicKey := "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1wn1sU/8Q0rYLlZ6sq3enrPZw2ptp6FecHR2bBFLjJ+sKzepROd0bKddgj+Mr1ffr3Ej78mLdWV8IzLfpXUi945DkrQcOUWLY0MHhYVG2jSs/qzFfpzmtut2Cl2TozYpE84zom9ei06u2AXLMBkU6VpznZl+R4qIgnUfByt3Ix5b3h4Cl6gzXMAB1hJrrrCkq+WvWb3Fy0vmk/DUbJEz8i8mQPff2gsHBE1nMPvHVAMw1GMk9ImB4PxucVek4ZbUzVqxZXphaAgUXFK2FSFU+Q+q1SPvHbUsjtIyL+cLA6H/6ybFF9Ffp27Y14AHPw29+243/SpMisbGcj2KD+evBwIDAQAB"
 	privateKey := "MIIEogIBAAKCAQEAy+CRzKw4krA2RzCDTqg5KJg92XkOY0RN3pW4sYInPqnGtHV7YDHu5nMuxY6un+dLfo91OFOEg+RI+WTOPoM4xJtsOaJwQ1lpjycoeLq1OyetGW5Q8wO+iLWJASaMQM/t/aXR/JHaguycJyqlHSlxANvKKs/tOHx9AhW3LqumaCwz71CDF/+70scYuZG/7wxSjmrbRBswxd1Sz9KHdcdjqT8pmieyPqnM24EKBexHDmQ0ySXvLJJy6eu1dJsPIz+ivX6HEfDXmSmJ71AZVqZyCI1MhK813R5E7XCv5NOtskTe3y8uiIhgGpZSdB77DOyPLcmVayzFVLAQ3AOBDmsY6wIDAQABAoIBAHjsNq31zAw9FcR9orQJlPVd7vlJEt6Pybvmg8hNESfanO+16rpwg2kOEkS8zxgqoJ1tSzJgXu23fgzl3Go5fHcoVDWPAhUAOFre9+M7onh2nPXDd6Hbq6v8OEmFapSaf2b9biHnBHq5Chk08v/r74l501w3PVVOiPqulJrK1oVb+0/YmCvVFpGatBcNaefKUEcA+vekWPL7Yl46k6XeUvRfTwomCD6jpYLUhsAKqZiQJhMGoaLglZvkokQMF/4G78K7FbbVLMM1+JDh8zJ/DDVdY2vHREUcCGhl4mCVQtkzIbpxG++vFg7/g/fDI+PquG22hFILTDdtt2g2fV/4wmkCgYEA6goRQYSiM03y8Tt/M4u1Mm7OWYCksqAsU7rzQllHekIN3WjD41Xrjv6uklsX3sTG1syo7Jr9PGE1xQgjDEIyO8h/3lDQyLyycYnyUPGNNMX8ZjmGwcM51DQ/QfIrY/CXjnnW+MVpmNclAva3L33KXCWjw20VsROV1EA8LCL94BUCgYEA3wH4ANpzo7NqXf+2WlPPMuyRrF0QPIRGlFBNtaKFy0mvoclkREPmK7+N4NIGtMf5JNODS5HkFRgmU4YNdupA2I8lIYpD+TsIobZxGUKUkYzRZYZ1m1ttL69YYvCVz9Xosw/VoQ+RrW0scS5yUKqFMIUOV2R/Imi//c5TdKx6VP8CgYAnJ1ADugC4vI2sNdvt7618pnT3HEJxb8J6r4gKzYzbszlGlURQQAuMfKcP7RVtO1ZYkRyhmLxM4aZxNA9I+boVrlFWDAchzg+8VuunBwIslgLHx0/4EoUWLzd1/OGtco6oU1HXhI9J9pRGjqfO1iiIifN/ujwqx7AFNknayG/YkQKBgD6yNgA/ak12rovYzXKdp14Axn+39k2dPp6J6R8MnyLlB3yruwW6NSbNhtzTD1GZ+wCQepQvYvlPPc8zm+t3tl1r+Rtx3ORf5XBZc3iPkGdPOLubTssrrAnA+U9vph61W+OjqwLJ9sHUNK9pSHhHSIS4k6ycM2YAHyIC9NGTgB0PAoGAJjwd1DgMaQldtWnuXjvohPOo8cQudxXYcs6zVRbx6vtjKe2v7e+eK1SSVrR5qFV9AqxDfGwq8THenRa0LC3vNNplqostuehLhkWCKE7Y75vXMR7N6KU1kdoVWgN4BhXSwuRxmHMQfSY7q3HG3rDGz7mzXo1FVMr/uE4iDGm0IXY="
 	//初始化支付宝客户端
 	//    appId:应用ID
 	//    privateKey:应用秘钥
 	//    isProd:是否是正式环境
-	client := gopay.NewAliPayClient("2016091200494382", privateKey, false)
+	client := alipay.NewClient("2016091200494382", privateKey, false)
 	//配置公共参数
 	client.SetCharset("utf-8").
 		SetSignType("RSA2")
@@ -22,7 +23,7 @@ func AliPayTradeFastPayRefundQuery() {
 	body.Set("out_trade_no", "GZ201907301420334577")
 	body.Set("out_request_no", "GZ201907301420334577")
 	//发起退款查询请求
-	aliRsp, err := client.AliPayTradeFastPayRefundQuery(body)
+	aliRsp, err := client.TradeFastPayRefundQuery(body)
 	if err != nil {
 		fmt.Println("err:", err)
 		return

+ 6 - 5
examples/alipay/alipay_AliPayTradeOrderSettle.go

@@ -4,15 +4,16 @@ import (
 	"fmt"
 
 	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/alipay"
 )
 
-func AliPayTradeOrderSettle() {
+func TradeOrderSettle() {
 	privateKey := "MIIEogIBAAKCAQEAy+CRzKw4krA2RzCDTqg5KJg92XkOY0RN3pW4sYInPqnGtHV7YDHu5nMuxY6un+dLfo91OFOEg+RI+WTOPoM4xJtsOaJwQ1lpjycoeLq1OyetGW5Q8wO+iLWJASaMQM/t/aXR/JHaguycJyqlHSlxANvKKs/tOHx9AhW3LqumaCwz71CDF/+70scYuZG/7wxSjmrbRBswxd1Sz9KHdcdjqT8pmieyPqnM24EKBexHDmQ0ySXvLJJy6eu1dJsPIz+ivX6HEfDXmSmJ71AZVqZyCI1MhK813R5E7XCv5NOtskTe3y8uiIhgGpZSdB77DOyPLcmVayzFVLAQ3AOBDmsY6wIDAQABAoIBAHjsNq31zAw9FcR9orQJlPVd7vlJEt6Pybvmg8hNESfanO+16rpwg2kOEkS8zxgqoJ1tSzJgXu23fgzl3Go5fHcoVDWPAhUAOFre9+M7onh2nPXDd6Hbq6v8OEmFapSaf2b9biHnBHq5Chk08v/r74l501w3PVVOiPqulJrK1oVb+0/YmCvVFpGatBcNaefKUEcA+vekWPL7Yl46k6XeUvRfTwomCD6jpYLUhsAKqZiQJhMGoaLglZvkokQMF/4G78K7FbbVLMM1+JDh8zJ/DDVdY2vHREUcCGhl4mCVQtkzIbpxG++vFg7/g/fDI+PquG22hFILTDdtt2g2fV/4wmkCgYEA6goRQYSiM03y8Tt/M4u1Mm7OWYCksqAsU7rzQllHekIN3WjD41Xrjv6uklsX3sTG1syo7Jr9PGE1xQgjDEIyO8h/3lDQyLyycYnyUPGNNMX8ZjmGwcM51DQ/QfIrY/CXjnnW+MVpmNclAva3L33KXCWjw20VsROV1EA8LCL94BUCgYEA3wH4ANpzo7NqXf+2WlPPMuyRrF0QPIRGlFBNtaKFy0mvoclkREPmK7+N4NIGtMf5JNODS5HkFRgmU4YNdupA2I8lIYpD+TsIobZxGUKUkYzRZYZ1m1ttL69YYvCVz9Xosw/VoQ+RrW0scS5yUKqFMIUOV2R/Imi//c5TdKx6VP8CgYAnJ1ADugC4vI2sNdvt7618pnT3HEJxb8J6r4gKzYzbszlGlURQQAuMfKcP7RVtO1ZYkRyhmLxM4aZxNA9I+boVrlFWDAchzg+8VuunBwIslgLHx0/4EoUWLzd1/OGtco6oU1HXhI9J9pRGjqfO1iiIifN/ujwqx7AFNknayG/YkQKBgD6yNgA/ak12rovYzXKdp14Axn+39k2dPp6J6R8MnyLlB3yruwW6NSbNhtzTD1GZ+wCQepQvYvlPPc8zm+t3tl1r+Rtx3ORf5XBZc3iPkGdPOLubTssrrAnA+U9vph61W+OjqwLJ9sHUNK9pSHhHSIS4k6ycM2YAHyIC9NGTgB0PAoGAJjwd1DgMaQldtWnuXjvohPOo8cQudxXYcs6zVRbx6vtjKe2v7e+eK1SSVrR5qFV9AqxDfGwq8THenRa0LC3vNNplqostuehLhkWCKE7Y75vXMR7N6KU1kdoVWgN4BhXSwuRxmHMQfSY7q3HG3rDGz7mzXo1FVMr/uE4iDGm0IXY="
 	//初始化支付宝客户端
 	//    appId:应用ID
 	//    privateKey:应用秘钥
 	//    isProd:是否是正式环境
-	client := gopay.NewAliPayClient("2016091200494382", privateKey, false)
+	client := alipay.NewClient("2016091200494382", privateKey, false)
 	//配置公共参数
 	client.SetCharset("utf-8").
 		SetSignType("RSA2")
@@ -21,14 +22,14 @@ func AliPayTradeOrderSettle() {
 	body.Set("out_request_no", "201907301518083384")
 	body.Set("trade_no", "2019072522001484690549776067")
 
-	var listParams []gopay.OpenApiRoyaltyDetailInfoPojo
-	listParams = append(listParams, gopay.OpenApiRoyaltyDetailInfoPojo{"transfer", "2088802095984694", "userId", "userId", "2088102363632794", "0.01", "分账给2088102363632794"})
+	var listParams []alipay.OpenApiRoyaltyDetailInfoPojo
+	listParams = append(listParams, alipay.OpenApiRoyaltyDetailInfoPojo{"transfer", "2088802095984694", "userId", "userId", "2088102363632794", "0.01", "分账给2088102363632794"})
 
 	body.Set("royalty_parameters", listParams)
 	fmt.Println("listParams:", body.Get("royalty_parameters"))
 
 	//发起交易结算接口
-	aliRsp, err := client.AliPayTradeOrderSettle(body)
+	aliRsp, err := client.TradeOrderSettle(body)
 	if err != nil {
 		fmt.Println("err:", err)
 		return

+ 2 - 1
examples/alipay/alipay_AliPayTradePagePay.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 
 	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/alipay"
 )
 
 func AliPayTradePagePay() {
@@ -13,7 +14,7 @@ func AliPayTradePagePay() {
 	//    appId:应用ID
 	//    privateKey:应用秘钥
 	//    isProd:是否是正式环境
-	client := gopay.NewAliPayClient("2016091200494382", privateKey, false)
+	client := alipay.NewClient("2016091200494382", privateKey, false)
 	//配置公共参数
 	client.SetCharset("utf-8").
 		SetSignType("RSA2").

+ 3 - 2
examples/alipay/alipay_AliPayTradePay.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 
 	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/alipay"
 )
 
 func AliPayTradePay() {
@@ -13,7 +14,7 @@ func AliPayTradePay() {
 	//    appId:应用ID
 	//    privateKey:应用秘钥
 	//    isProd:是否是正式环境
-	client := gopay.NewAliPayClient("2016091200494382", privateKey, false)
+	client := alipay.NewClient("2016091200494382", privateKey, false)
 	//配置公共参数
 	client.SetCharset("utf-8").
 		SetSignType("RSA2").
@@ -36,7 +37,7 @@ func AliPayTradePay() {
 	fmt.Println("aliRsp:", *aliRsp)
 	// 同步返回验签
 	alipayPublicKey := "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAp8gueNlkbiDidz6FBQEBpqoRgH8h7JtsPtYW0nzAqy1MME4mFnDSMfSKlreUomS3a55gmBopL1eF4/Km/dEnaL5tCY9+24SKn1D4iyls+lvz/ZjvUjVwxoUYBh8kkcxMZSDeDz8//o+9qZTrICVP2a4sBB8T0XmU4gxfw8FsmtoomBH1nLk3AO7wgRN2a3+SRSAmxrhIGDmF1lljSlhY32eJpJ2TZQKaWNW+7yDBU/0Wt3kQVY84vr14yYagnSCiIfqyVFqePayRtmVJDr5qvSXr51tdqs2zKZCu+26X7JAF4BSsaq4gmY5DmDTm4TohCnBduI1+bPGD+igVmtl05wIDAQAB"
-	ok, err := gopay.VerifyAliPaySyncSign(alipayPublicKey, aliRsp.SignData, aliRsp.Sign)
+	ok, err := alipay.VerifySyncSign(alipayPublicKey, aliRsp.SignData, aliRsp.Sign)
 	if err != nil {
 		fmt.Println("err:::", err)
 	}

+ 2 - 1
examples/alipay/alipay_AliPayTradePrecreate.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 
 	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/alipay"
 )
 
 func AliPayTradePrecreate() {
@@ -12,7 +13,7 @@ func AliPayTradePrecreate() {
 	//    appId:应用ID
 	//    privateKey:应用秘钥
 	//    isProd:是否是正式环境
-	client := gopay.NewAliPayClient("2016091200494382", privateKey, false)
+	client := alipay.NewClient("2016091200494382", privateKey, false)
 	//配置公共参数
 	client.SetCharset("utf-8").
 		SetSignType("RSA2").

+ 2 - 1
examples/alipay/alipay_AliPayTradeQuery.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 
 	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/alipay"
 )
 
 func AliPayTradeQuery() {
@@ -13,7 +14,7 @@ func AliPayTradeQuery() {
 	//    appId:应用ID
 	//    privateKey:应用秘钥
 	//    isProd:是否是正式环境
-	client := gopay.NewAliPayClient("2016091200494382", privateKey, false)
+	client := alipay.NewClient("2016091200494382", privateKey, false)
 	//配置公共参数
 	client.SetCharset("utf-8").
 		SetSignType("RSA2").

+ 2 - 1
examples/alipay/alipay_AliPayTradeRefund.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 
 	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/alipay"
 )
 
 func AliPayTradeRefund() {
@@ -13,7 +14,7 @@ func AliPayTradeRefund() {
 	//    appId:应用ID
 	//    privateKey:应用秘钥
 	//    isProd:是否是正式环境
-	client := gopay.NewAliPayClient("2016091200494382", privateKey, false)
+	client := alipay.NewClient("2016091200494382", privateKey, false)
 	//配置公共参数
 	client.SetCharset("utf-8").
 		SetSignType("RSA2")

+ 2 - 1
examples/alipay/alipay_AliPayTradeWapPay.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 
 	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/alipay"
 )
 
 func AliPayTradeWapPay() {
@@ -13,7 +14,7 @@ func AliPayTradeWapPay() {
 	//    appId:应用ID
 	//    privateKey:应用秘钥
 	//    isProd:是否是正式环境
-	client := gopay.NewAliPayClient("2016091200494382", privateKey, false)
+	client := alipay.NewClient("2016091200494382", privateKey, false)
 	//配置公共参数
 	client.SetCharset("utf-8").
 		SetSignType("RSA2").

+ 2 - 1
examples/alipay/alipay_AliPayUserCertifyOpenCertify.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 
 	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/alipay"
 )
 
 func AliPayUserCertifyOpenCertify() {
@@ -13,7 +14,7 @@ func AliPayUserCertifyOpenCertify() {
 	//    appId:应用ID
 	//    privateKey:应用秘钥
 	//    isProd:是否是正式环境
-	client := gopay.NewAliPayClient("2016091200494382", privateKey, false)
+	client := alipay.NewClient("2016091200494382", privateKey, false)
 	//配置公共参数
 	client.SetCharset("utf-8").
 		SetSignType("RSA2")

+ 2 - 1
examples/alipay/alipay_AliPayUserCertifyOpenInit.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 
 	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/alipay"
 )
 
 func AliPayUserCertifyOpenInit() {
@@ -13,7 +14,7 @@ func AliPayUserCertifyOpenInit() {
 	//    appId:应用ID
 	//    privateKey:应用秘钥
 	//    isProd:是否是正式环境
-	client := gopay.NewAliPayClient("2016091200494382", privateKey, false)
+	client := alipay.NewClient("2016091200494382", privateKey, false)
 	//配置公共参数
 	client.SetCharset("utf-8").
 		SetSignType("RSA2")

+ 2 - 1
examples/alipay/alipay_AliPayUserCertifyOpenQuery.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 
 	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/alipay"
 )
 
 func AliPayUserCertifyOpenQuery() {
@@ -13,7 +14,7 @@ func AliPayUserCertifyOpenQuery() {
 	//    appId:应用ID
 	//    privateKey:应用秘钥
 	//    isProd:是否是正式环境
-	client := gopay.NewAliPayClient("2016091200494382", privateKey, false)
+	client := alipay.NewClient("2016091200494382", privateKey, false)
 	//配置公共参数
 	client.SetCharset("utf-8").
 		SetSignType("RSA2")

+ 2 - 1
examples/alipay/alipay_AlipayFundTransToaccountTransfer.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 
 	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/alipay"
 )
 
 func AliPayFundTransToaccountTransfer() {
@@ -12,7 +13,7 @@ func AliPayFundTransToaccountTransfer() {
 	//    appId:应用ID
 	//    privateKey:应用秘钥
 	//    isProd:是否是正式环境
-	client := gopay.NewAliPayClient("2016091200494382", privateKey, false)
+	client := alipay.NewClient("2016091200494382", privateKey, false)
 	//配置公共参数
 	client.SetCharset("utf-8").
 		SetSignType("RSA2")

+ 2 - 1
examples/alipay/alipay_AlipayOpenAuthTokenApp.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 
 	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/alipay"
 )
 
 func AliPayOpenAuthTokenApp() {
@@ -13,7 +14,7 @@ func AliPayOpenAuthTokenApp() {
 	//    appId:应用ID
 	//    privateKey:应用秘钥
 	//    isProd:是否是正式环境
-	client := gopay.NewAliPayClient("2016091200494382", privateKey, false)
+	client := alipay.NewClient("2016091200494382", privateKey, false)
 	//配置公共参数
 	client.SetCharset("utf-8").
 		SetSignType("RSA2")

+ 4 - 4
examples/alipay/alipay_AlipayUserInfoShare.go

@@ -3,7 +3,7 @@ package alipay
 import (
 	"fmt"
 
-	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/alipay"
 )
 
 func AliPayUserInfoShare() {
@@ -13,7 +13,7 @@ func AliPayUserInfoShare() {
 	//    appId:应用ID
 	//    privateKey:应用秘钥
 	//    isProd:是否是正式环境
-	client := gopay.NewAliPayClient("2016091200494382", privateKey, false)
+	client := alipay.NewClient("2016091200494382", privateKey, false)
 	//配置公共参数
 	client.SetCharset("utf-8").
 		SetSignType("RSA2").
@@ -27,9 +27,9 @@ func AliPayUserInfoShare() {
 	}
 	fmt.Println("aliRsp:", *aliRsp)
 	// 同步返回验签
-	ok, err := gopay.VerifyAliPaySyncSign(aliPayPublicKey, aliRsp.SignData, aliRsp.Sign)
+	ok, err := alipay.VerifySyncSign(aliPayPublicKey, aliRsp.SignData, aliRsp.Sign)
 	if err != nil {
-		fmt.Println("VerifyAliPaySign-err:", err)
+		fmt.Println("VerifySign-err:", err)
 		return
 	}
 	fmt.Println("ok:", ok)

+ 12 - 12
examples/alipay/alipay_ServiceApi.go

@@ -5,28 +5,28 @@ import (
 	"log"
 	"net/http"
 
-	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/alipay"
 )
 
 func FormatPrivateKey() {
 	privateKey := "MIIEowIBAAKCAQEAxorj0SisU93LxawVWybZzDYfq8bxzw9VIOKDSW1M5ombl/MvZTT9IuBSGvqUxXFSWqY05e+CBlquFrOHTzKttmzeZJEKHpGAkW+4TsX6N4ZCHfz3Sz5MBAzBqQvscUD0FTZ+VlQbQ1HjQiKLbHaNY+fFVn3q2XL6dNtWwFhad592M1lCbzEjZ7yqFcxJ0jIDBh1lWwemHu52iW3YkvLD5lE8IXRiJedhgPFXCFAkX5HLcc0/jicRTarQ9gRNpHC6B87T2SDjKmgxqcws4CVdYJbztU1KLrsbMALFMOp24x8xsLgR88XeraQyUWe6V3lt1OYEOd9XLHWRx33bRHSwIDAQABAoIBAHjrGfjG1r11Nae8OH19WeRfikZqMdcztVsD2YWcxdsaL+MJPvJapVjaWecIehcN/2QqGcl4Zy5Lh/9Xc68uZFHYWFHTa+BWKYFqE0wWk1/Bqv7slAgFdvJ4enHkSypmrsFEoQkezEPh2ZDrzRJP2ajg/XTB14h72EHXXCxlIyP6q9ldlHyYSc+KOdC3WYOg1FoFXsliZHVKGZUxo4jck+xwdTGRAIKYpdLjpw7DqAWS6N25cx4XK9GuBYoV7AkIM0kpdjDDXAciG2aws6ef4kumWuW/JSbdrFWGLdiAN8GVpBx6+9WTeDKerS9KyDLNf6rsz9Hm3LNWOYCMLlrEFiECgYEA/XB6pZGrbmSebn2lZO+WFs3LYCXoCUy4ePouLYZO7lKsHNeTYRxCc6cbEmap0hpuMCYVPJkqK+nL/CDwBad1QChN5rPVFl2rLtLu0owvoAuTVjWjYNPgDfWb3spXh0p+lZ9oi53kZd4iDGe/jQJzAcpUa3Yj2me6XFFTD+8FNCkCgYEAyIxrkCo2oqGg1aJ7xc9+aBcpsrVg/upptdTgiMGSVZ3XuixufZV36lzJOdmCBoFGKwmLgKkStJSOm3SHUqdEKQBbHI95aG3HgnAMRXOtkn1exExfpAmCnAAnAx8RONorOTjrMrW0BO0/NII7O7NkLg/ocahr/lXEylsC8dLlMCgYBDiwiEu6/Oee5nUAEWR2veo/YBp9iRMeswAqzv4Q2EInBQN3vFs7xaCj0CyG2V2wlmt5+NSNyeW27LwRN2zkxHTvaD94VgspH+pqSTZF0E8FDR9vWVxqG91qk11QNCwS2/Pn6kRu4p3+t/Ft9L+00fOwcIpLGlcWOPWvUiF/dxEQKBgQCNEEhwpWC80FejLaFGKIdPjEtmSrKpXBV0rfTF+LkizuUBJ3/9zQNRyeGxnnuRj+nlvO1e3sWACySHRu4G53MvR8qqVr13ecfuuA0nOvPojuq4THKrlzVsUqGelXBrlEdiFFJMY7axfvBzoYIyqq+aoTxFjJ6Z/czFOZyp6tnpxQKBgClvDZ9pUc+WH28fDnDPd36bC6HmBq/fkxo92RJey1aRFSoCtKNW5Eaqem8iDD+WAVYak2Vg7xUHkhwIEyVVfHIxZBXc0X1w3jNFjG1/Fyul4hLjqCH2QI8gOjHXAcDZe+MJa8b33ZTiiilUu5A0N8+Xz8qpMQ84cXODHJcPMPYb"
 
-	pKey := gopay.FormatPrivateKey(privateKey)
+	pKey := alipay.FormatPrivateKey(privateKey)
 	fmt.Println(pKey)
 }
 
 func FormatAliPayPublicKey() {
 	aliPayPublicKey := "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAp8gueNlkbiDidz6FBQEBpqoRgH8h7JtsPtYW0nzAqy1MME4mFnDSMfSKlreUomS3a55gmBopL1eF4/Km/dEnaL5tCY9+24SKn1D4iyls+lvz/ZjvUjVwxoUYBh8kkcxMZSDeDz8//o+9qZTrICVP2a4sBB8T0XmU4gxfw8FsmtoomBH1nLk3AO7wgRN2a3+SRSAmxrhIGDmF1lljSlhY32eJpJ2TZQKaWNW+7yDBU/0Wt3kQVY84vr14yYagnSCiIfqyVFqePayRtmVJDr5qvSXr51tdqs2zKZCu+26X7JAF4BSsaq4gmY5DmDTm4TohCnBduI1+bPGD+igVmtl05wIDAQAB"
 
-	pKey := gopay.FormatAliPayPublicKey(aliPayPublicKey)
+	pKey := alipay.FormatPublicKey(aliPayPublicKey)
 	fmt.Println(pKey)
 }
 
 func AliPaySystemOauthToken2() {
 	privateKey := "MIIEogIBAAKCAQEAy+CRzKw4krA2RzCDTqg5KJg92XkOY0RN3pW4sYInPqnGtHV7YDHu5nMuxY6un+dLfo91OFOEg+RI+WTOPoM4xJtsOaJwQ1lpjycoeLq1OyetGW5Q8wO+iLWJASaMQM/t/aXR/JHaguycJyqlHSlxANvKKs/tOHx9AhW3LqumaCwz71CDF/+70scYuZG/7wxSjmrbRBswxd1Sz9KHdcdjqT8pmieyPqnM24EKBexHDmQ0ySXvLJJy6eu1dJsPIz+ivX6HEfDXmSmJ71AZVqZyCI1MhK813R5E7XCv5NOtskTe3y8uiIhgGpZSdB77DOyPLcmVayzFVLAQ3AOBDmsY6wIDAQABAoIBAHjsNq31zAw9FcR9orQJlPVd7vlJEt6Pybvmg8hNESfanO+16rpwg2kOEkS8zxgqoJ1tSzJgXu23fgzl3Go5fHcoVDWPAhUAOFre9+M7onh2nPXDd6Hbq6v8OEmFapSaf2b9biHnBHq5Chk08v/r74l501w3PVVOiPqulJrK1oVb+0/YmCvVFpGatBcNaefKUEcA+vekWPL7Yl46k6XeUvRfTwomCD6jpYLUhsAKqZiQJhMGoaLglZvkokQMF/4G78K7FbbVLMM1+JDh8zJ/DDVdY2vHREUcCGhl4mCVQtkzIbpxG++vFg7/g/fDI+PquG22hFILTDdtt2g2fV/4wmkCgYEA6goRQYSiM03y8Tt/M4u1Mm7OWYCksqAsU7rzQllHekIN3WjD41Xrjv6uklsX3sTG1syo7Jr9PGE1xQgjDEIyO8h/3lDQyLyycYnyUPGNNMX8ZjmGwcM51DQ/QfIrY/CXjnnW+MVpmNclAva3L33KXCWjw20VsROV1EA8LCL94BUCgYEA3wH4ANpzo7NqXf+2WlPPMuyRrF0QPIRGlFBNtaKFy0mvoclkREPmK7+N4NIGtMf5JNODS5HkFRgmU4YNdupA2I8lIYpD+TsIobZxGUKUkYzRZYZ1m1ttL69YYvCVz9Xosw/VoQ+RrW0scS5yUKqFMIUOV2R/Imi//c5TdKx6VP8CgYAnJ1ADugC4vI2sNdvt7618pnT3HEJxb8J6r4gKzYzbszlGlURQQAuMfKcP7RVtO1ZYkRyhmLxM4aZxNA9I+boVrlFWDAchzg+8VuunBwIslgLHx0/4EoUWLzd1/OGtco6oU1HXhI9J9pRGjqfO1iiIifN/ujwqx7AFNknayG/YkQKBgD6yNgA/ak12rovYzXKdp14Axn+39k2dPp6J6R8MnyLlB3yruwW6NSbNhtzTD1GZ+wCQepQvYvlPPc8zm+t3tl1r+Rtx3ORf5XBZc3iPkGdPOLubTssrrAnA+U9vph61W+OjqwLJ9sHUNK9pSHhHSIS4k6ycM2YAHyIC9NGTgB0PAoGAJjwd1DgMaQldtWnuXjvohPOo8cQudxXYcs6zVRbx6vtjKe2v7e+eK1SSVrR5qFV9AqxDfGwq8THenRa0LC3vNNplqostuehLhkWCKE7Y75vXMR7N6KU1kdoVWgN4BhXSwuRxmHMQfSY7q3HG3rDGz7mzXo1FVMr/uE4iDGm0IXY="
-	rsp, err := gopay.AliPaySystemOauthToken("2016091200494382", privateKey, "", "06e8961891d647c0ac99bb1cebe7SE69")
+	rsp, err := alipay.AliPaySystemOauthToken("2016091200494382", privateKey, "", "06e8961891d647c0ac99bb1cebe7SE69")
 	if err != nil {
-		fmt.Println("gopay.AliPaySystemOauthToken:", err)
+		fmt.Println("gopay.SystemOauthToken:", err)
 		return
 	}
 	fmt.Println("rsp:", *rsp)
@@ -35,8 +35,8 @@ func AliPaySystemOauthToken2() {
 func DecryptAliPayOpenDataToStruct() {
 	data := "MkvuiIZsGOC8S038cu/JIpoRKnF+ZFjoIRGf5d/K4+ctYjCtb/eEkwgrdB5TeH/93bxff1Ylb+SE+UGStlpvcg=="
 	key := "TDftre9FpItr46e9BVNJcw=="
-	rsp := new(gopay.AliPayUserPhone)
-	err := gopay.DecryptAliPayOpenDataToStruct(data, key, rsp)
+	rsp := new(alipay.AliPayUserPhone)
+	err := alipay.DecryptAliPayOpenDataToStruct(data, key, rsp)
 	if err != nil {
 		fmt.Println("err:", err)
 		return
@@ -53,7 +53,7 @@ func VerifyAliPaySyncSign() {
 	signData := "aaaaaaaaaaaaaaaaaaaaaa"
 	sign := "asdkjsdhfgkjdshflksdjfl"
 
-	ok, err := gopay.VerifyAliPaySyncSign(aliPayPublicKey, signData, sign)
+	ok, err := alipay.VerifySyncSign(aliPayPublicKey, signData, sign)
 	if err != nil {
 		fmt.Println("err:", err)
 		return
@@ -65,7 +65,7 @@ func ParseAliPayNotifyResultAndVerifyAliPaySign(req *http.Request) {
 	aliPayPublicKey := "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1wn1sU/8Q0rYLlZ6sq3enrPZw2ptp6FecHR2bBFLjJ+sKzepROd0bKddgj+Mr1ffr3Ej78mLdWV8IzLfpXUi945DkrQcOUWLY0MHhYVG2jSs/qzFfpzmtut2Cl2TozYpE84zom9ei06u2AXLMBkU6VpznZl+R4qIgnUfByt3Ix5b3h4Cl6gzXMAB1hJrrrCkq+WvWb3Fy0vmk/DUbJEz8i8mQPff2gsHBE1nMPvHVAMw1GMk9ImB4PxucVek4ZbUzVqxZXphaAgUXFK2FSFU+Q+q1SPvHbUsjtIyL+cLA6H/6ybFF9Ffp27Y14AHPw29+243/SpMisbGcj2KD+evBwIDAQAB"
 
 	//解析请求参数
-	notifyReq, err := gopay.ParseAliPayNotifyResult(req)
+	notifyReq, err := alipay.ParseNotifyResult(req)
 	if err != nil {
 		fmt.Println("err:", err)
 		return
@@ -73,7 +73,7 @@ func ParseAliPayNotifyResultAndVerifyAliPaySign(req *http.Request) {
 	fmt.Println("notifyReq:", *notifyReq)
 
 	//验签
-	ok, err := gopay.VerifyAliPaySign(aliPayPublicKey, notifyReq)
+	ok, err := alipay.VerifySign(aliPayPublicKey, notifyReq)
 	if err != nil {
 		fmt.Println("err:", err)
 		return
@@ -82,14 +82,14 @@ func ParseAliPayNotifyResultAndVerifyAliPaySign(req *http.Request) {
 }
 
 func GetCertSN() {
-	sn, err := gopay.GetCertSN("alipay_cert/appCertPublicKey.crt")
+	sn, err := alipay.GetCertSN("alipay_cert/appCertPublicKey.crt")
 	if err != nil {
 		fmt.Println("err:", err)
 		return
 	}
 	fmt.Println("sn:", sn)
 
-	sn, err = gopay.GetCertSN("alipay_cert/alipayCertPublicKey_RSA2.crt")
+	sn, err = alipay.GetCertSN("alipay_cert/alipayCertPublicKey_RSA2.crt")
 	if err != nil {
 		fmt.Println("err:", err)
 		return

+ 2 - 1
examples/alipay/alipay_ZhimaCreditScoreGet.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 
 	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/alipay"
 )
 
 func ZhimaCreditScoreGet() {
@@ -12,7 +13,7 @@ func ZhimaCreditScoreGet() {
 	//    appId:应用ID
 	//    privateKey:应用秘钥
 	//    isProd:是否是正式环境
-	client := gopay.NewAliPayClient("2016091200494382", privateKey, false)
+	client := alipay.NewClient("2016091200494382", privateKey, false)
 	//配置公共参数
 	client.SetCharset("utf-8").
 		SetSignType("RSA2").

+ 3 - 2
examples/wechat/wx_BatchQueryComment.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 
 	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/wechat"
 )
 
 func BatchQueryComment() {
@@ -13,12 +14,12 @@ func BatchQueryComment() {
 	//    ApiKey:Key值
 	//    isProd:是否是正式环境
 	//    好像不支持沙箱环境,因为沙箱环境默认需要用MD5签名,但是此接口仅支持HMAC-SHA256签名
-	client := gopay.NewWeChatClient("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", false)
+	client := wechat.NewClient("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", false)
 
 	//初始化参数结构体
 	body := make(gopay.BodyMap)
 	body.Set("nonce_str", gopay.GetRandomString(32))
-	body.Set("sign_type", gopay.SignType_HMAC_SHA256)
+	body.Set("sign_type", wechat.SignType_HMAC_SHA256)
 	body.Set("begin_time", "20190120000000")
 	body.Set("end_time", "20190122174000")
 	body.Set("offset", "0")

+ 3 - 2
examples/wechat/wx_CloseOrder.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 
 	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/wechat"
 )
 
 func CloseOrder() {
@@ -12,13 +13,13 @@ func CloseOrder() {
 	//    MchID:商户ID
 	//    ApiKey:Key值
 	//    isProd:是否是正式环境
-	client := gopay.NewWeChatClient("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", false)
+	client := wechat.NewClient("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", false)
 
 	//初始化参数结构体
 	body := make(gopay.BodyMap)
 	body.Set("out_trade_no", "MfZC2segKxh0bnJSELbvKNeH3d9oWvvQ")
 	body.Set("nonce_str", gopay.GetRandomString(32))
-	body.Set("sign_type", gopay.SignType_MD5)
+	body.Set("sign_type", wechat.SignType_MD5)
 
 	//请求关闭订单,成功后得到结果
 	wxRsp, err := client.CloseOrder(body)

+ 3 - 2
examples/wechat/wx_DownloadBill.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 
 	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/wechat"
 )
 
 func DownloadBill() {
@@ -12,12 +13,12 @@ func DownloadBill() {
 	//    MchID:商户ID
 	//    ApiKey:Key值
 	//    isProd:是否是正式环境
-	client := gopay.NewWeChatClient("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", false)
+	client := wechat.NewClient("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", false)
 
 	//初始化参数结构体
 	body := make(gopay.BodyMap)
 	body.Set("nonce_str", gopay.GetRandomString(32))
-	body.Set("sign_type", gopay.SignType_MD5)
+	body.Set("sign_type", wechat.SignType_MD5)
 	body.Set("bill_date", "20190722")
 	body.Set("bill_type", "ALL")
 

+ 3 - 2
examples/wechat/wx_DownloadFundFlow.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 
 	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/wechat"
 )
 
 func DownloadFundFlow() {
@@ -13,12 +14,12 @@ func DownloadFundFlow() {
 	//    ApiKey:Key值
 	//    isProd:是否是正式环境
 	//    好像不支持沙箱环境,因为沙箱环境默认需要用MD5签名,但是此接口仅支持HMAC-SHA256签名
-	client := gopay.NewWeChatClient("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", false)
+	client := wechat.NewClient("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", false)
 
 	//初始化参数结构体
 	body := make(gopay.BodyMap)
 	body.Set("nonce_str", gopay.GetRandomString(32))
-	body.Set("sign_type", gopay.SignType_HMAC_SHA256)
+	body.Set("sign_type", wechat.SignType_HMAC_SHA256)
 	body.Set("bill_date", "20190122")
 	body.Set("account_type", "Basic")
 

+ 6 - 5
examples/wechat/wx_Micropay.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 
 	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/wechat"
 )
 
 func Micropay() {
@@ -12,7 +13,7 @@ func Micropay() {
 	//    MchID:商户ID
 	//    ApiKey:Key值
 	//    isProd:是否是正式环境
-	client := gopay.NewWeChatClient("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", false)
+	client := wechat.NewClient("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", false)
 
 	//初始化参数Map
 	body := make(gopay.BodyMap)
@@ -24,10 +25,10 @@ func Micropay() {
 	body.Set("total_fee", 1)
 	body.Set("spbill_create_ip", "127.0.0.1")
 	body.Set("auth_code", "134595229789828537")
-	body.Set("sign_type", gopay.SignType_MD5)
+	body.Set("sign_type", wechat.SignType_MD5)
 
-	sign := gopay.GetWeChatParamSign("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", body)
-	//sign, _ := gopay.GetWeChatSanBoxParamSign("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", body)
+	sign := wechat.GetParamSign("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", body)
+	//sign, _ := gopay.GetSanBoxParamSign("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", body)
 
 	body.Set("sign", sign)
 	//请求支付,成功后得到结果
@@ -38,7 +39,7 @@ func Micropay() {
 	}
 	fmt.Println("Response:", *wxRsp)
 
-	ok, err := gopay.VerifyWeChatSign("GFDS8j98rewnmgl45wHTt980jg543abc", gopay.SignType_MD5, wxRsp)
+	ok, err := wechat.VerifySign("GFDS8j98rewnmgl45wHTt980jg543abc", wechat.SignType_MD5, wxRsp)
 	if err != nil {
 		fmt.Println("err:", err)
 	}

+ 3 - 2
examples/wechat/wx_QueryOrder.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 
 	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/wechat"
 )
 
 func QueryOrder() {
@@ -12,13 +13,13 @@ func QueryOrder() {
 	//    MchID:商户ID
 	//    apiKey:API秘钥值
 	//    isProd:是否是正式环境
-	client := gopay.NewWeChatClient("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", false)
+	client := wechat.NewClient("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", false)
 
 	//初始化参数结构体
 	body := make(gopay.BodyMap)
 	body.Set("out_trade_no", "GW201908091551421156")
 	body.Set("nonce_str", gopay.GetRandomString(32))
-	body.Set("sign_type", gopay.SignType_MD5)
+	body.Set("sign_type", wechat.SignType_MD5)
 
 	//请求订单查询,成功后得到结果
 	wxRsp, err := client.QueryOrder(body)

+ 3 - 2
examples/wechat/wx_QueryRefund.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 
 	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/wechat"
 )
 
 func QueryRefund() {
@@ -12,7 +13,7 @@ func QueryRefund() {
 	//    MchID:商户ID
 	//    ApiKey:Key值
 	//    isProd:是否是正式环境
-	client := gopay.NewWeChatClient("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", false)
+	client := wechat.NewClient("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", false)
 
 	//初始化参数结构体
 	body := make(gopay.BodyMap)
@@ -21,7 +22,7 @@ func QueryRefund() {
 	//body.Set("transaction_id", "97HiM5j6kGmM2fk7fYMc8MgKhPnEQ5Rk")
 	//body.Set("refund_id", "97HiM5j6kGmM2fk7fYMc8MgKhPnEQ5Rk")
 	body.Set("nonce_str", gopay.GetRandomString(32))
-	body.Set("sign_type", gopay.SignType_MD5)
+	body.Set("sign_type", wechat.SignType_MD5)
 
 	//请求申请退款
 	wxRsp, err := client.QueryRefund(body)

+ 3 - 2
examples/wechat/wx_Refund.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 
 	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/wechat"
 )
 
 func Refund() {
@@ -12,13 +13,13 @@ func Refund() {
 	//    MchID:商户ID
 	//    ApiKey:Key值
 	//    isProd:是否是正式环境
-	client := gopay.NewWeChatClient("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", false)
+	client := wechat.NewClient("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", false)
 
 	//初始化参数结构体
 	body := make(gopay.BodyMap)
 	body.Set("out_trade_no", "SdZBAqJHBQGKVwb7aMR2mUwC588NG2Sd")
 	body.Set("nonce_str", gopay.GetRandomString(32))
-	body.Set("sign_type", gopay.SignType_MD5)
+	body.Set("sign_type", wechat.SignType_MD5)
 	s := gopay.GetRandomString(64)
 	fmt.Println("out_refund_no:", s)
 	body.Set("out_refund_no", s)

+ 3 - 2
examples/wechat/wx_Reverse.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 
 	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/wechat"
 )
 
 func Reverse() {
@@ -12,13 +13,13 @@ func Reverse() {
 	//    MchID:商户ID
 	//    ApiKey:Key值
 	//    isProd:是否是正式环境
-	client := gopay.NewWeChatClient("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", false)
+	client := wechat.NewClient("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", false)
 
 	//初始化参数Map
 	body := make(gopay.BodyMap)
 	body.Set("nonce_str", gopay.GetRandomString(32))
 	body.Set("out_trade_no", "6aDCor1nUcAihrV5JBlI09tLvXbUp02B")
-	body.Set("sign_type", gopay.SignType_MD5)
+	body.Set("sign_type", wechat.SignType_MD5)
 
 	//请求撤销订单,成功后得到结果,沙箱环境下,证书路径参数可传空
 	wxRsp, err := client.Reverse(body, "", "", "")

+ 21 - 20
examples/wechat/wx_ServiceApi.go

@@ -5,6 +5,7 @@ import (
 	"net/http"
 
 	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/wechat"
 )
 
 func Code2Session() {
@@ -12,7 +13,7 @@ func Code2Session() {
 	//    appId:APPID
 	//    appSecret:AppSecret
 	//    wxCode:小程序调用wx.login 获取的code
-	userIdRsp, err := gopay.Code2Session("AppID", "APPSecret", "011EZg6p0VO47n1p2W4p0mle6p0EZg6u")
+	userIdRsp, err := wechat.Code2Session("AppID", "APPSecret", "011EZg6p0VO47n1p2W4p0mle6p0EZg6u")
 	if err != nil {
 		fmt.Println("err:", err)
 		return
@@ -26,7 +27,7 @@ func Code2Session() {
 }
 
 func GetAppWeChatLoginAccessToken() {
-	accessToken, err := gopay.GetAppWeChatLoginAccessToken("AppID", "AppSecret", "code")
+	accessToken, err := wechat.GetAppLoginAccessToken("AppID", "AppSecret", "code")
 	if err != nil {
 		fmt.Println("err:", err)
 		return
@@ -41,7 +42,7 @@ func GetAppWeChatLoginAccessToken() {
 }
 
 func RefreshAppWeChatLoginAccessToken() {
-	accessToken, err := gopay.RefreshAppWeChatLoginAccessToken("AppID", "refreshToken")
+	accessToken, err := wechat.RefreshAppLoginAccessToken("AppID", "refreshToken")
 	if err != nil {
 		fmt.Println("err:", err)
 		return
@@ -58,7 +59,7 @@ func GetWeChatAppletAccessToken() {
 	//获取小程序全局唯一后台接口调用凭据(AccessToken:157字符)
 	//    appId:APPID
 	//    appSecret:AppSecret
-	accessToken, err := gopay.GetWeChatAppletAccessToken("AppID", "AppSecret")
+	accessToken, err := wechat.GetAppletAccessToken("AppID", "AppSecret")
 	if err != nil {
 		fmt.Println("err:", err)
 		return
@@ -75,7 +76,7 @@ func GetWeChatAppletPaidUnionId() {
 	//    accessToken:接口调用凭据
 	//    openId:用户的OpenID
 	//    transactionId:微信支付订单号
-	rsp, err := gopay.GetWeChatAppletPaidUnionId(accessToken, "o0Df70MSI4Ygv2KQ2cLnoMN5CXI8", "4200000326201905256499385970")
+	rsp, err := wechat.GetAppletPaidUnionId(accessToken, "o0Df70MSI4Ygv2KQ2cLnoMN5CXI8", "4200000326201905256499385970")
 	if err != nil {
 		fmt.Println("err:", err)
 		return
@@ -91,7 +92,7 @@ func GetWeChatUserInfo() {
 	//    accessToken:接口调用凭据
 	//    openId:用户的OpenID
 	//    lang:默认为 zh_CN ,可选填 zh_CN 简体,zh_TW 繁体,en 英语
-	userInfo, err := gopay.GetWeChatUserInfo(accessToken, "o0Df70H2Q0fY8JXh1aFPIRyOBgu8")
+	userInfo, err := wechat.GetUserInfo(accessToken, "o0Df70H2Q0fY8JXh1aFPIRyOBgu8")
 	if err != nil {
 		fmt.Println("err:", err)
 		return
@@ -105,13 +106,13 @@ func DecryptWeChatOpenDataToStruct() {
 	session := "lyY4HPQbaOYzZdG+JcYK9w=="
 
 	//微信小程序,手机号
-	phone := new(gopay.WeChatUserPhone)
+	phone := new(wechat.UserPhone)
 	//解密开放数据
 	//    encryptedData:包括敏感数据在内的完整用户信息的加密数据
 	//    iv:加密算法的初始向量
 	//    sessionKey:会话密钥
 	//    beanPtr:需要解析到的结构体指针
-	err := gopay.DecryptWeChatOpenDataToStruct(data, iv, session, phone)
+	err := wechat.DecryptOpenDataToStruct(data, iv, session, phone)
 	if err != nil {
 		fmt.Println("err:", err)
 		return
@@ -126,9 +127,9 @@ func DecryptWeChatOpenDataToStruct() {
 	iv2 := "r7BXXKkLb8qrSNn05n0qiA=="
 
 	//微信小程序 用户信息
-	userInfo := new(gopay.WeChatAppletUserInfo)
+	userInfo := new(wechat.AppletUserInfo)
 
-	err = gopay.DecryptWeChatOpenDataToStruct(encryptedData, iv2, sessionKey, userInfo)
+	err = wechat.DecryptOpenDataToStruct(encryptedData, iv2, sessionKey, userInfo)
 	if err != nil {
 		fmt.Println("err:", err)
 		return
@@ -153,7 +154,7 @@ func DecryptWeChatOpenDataToBodyMap() {
 	//    encryptedData:包括敏感数据在内的完整用户信息的加密数据
 	//    iv:加密算法的初始向量
 	//    sessionKey:会话密钥
-	bm, err := gopay.DecryptWeChatOpenDataToBodyMap(data, iv, session)
+	bm, err := wechat.DecryptOpenDataToBodyMap(data, iv, session)
 	if err != nil {
 		fmt.Println("err:", err)
 		return
@@ -168,7 +169,7 @@ func GetOpenIdByAuthCode() {
 	//    apiKey:ApiKey
 	//    authCode:用户授权码
 	//    nonceStr:随即字符串
-	openIdRsp, err := gopay.GetOpenIdByAuthCode("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", "135127679952609396", gopay.GetRandomString(32))
+	openIdRsp, err := wechat.GetOpenIdByAuthCode("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", "135127679952609396", gopay.GetRandomString(32))
 	if err != nil {
 		fmt.Println("err:", err)
 		return
@@ -185,17 +186,17 @@ func GetOpenIdByAuthCode() {
 
 //解析notify参数、验签、返回数据到微信
 func ParseWeChatNotifyResultAndVerifyWeChatSign(req *http.Request) string {
-	rsp := new(gopay.WeChatNotifyResponse)
+	rsp := new(wechat.NotifyResponse)
 
 	//解析参数
-	notifyReq, err := gopay.ParseWeChatNotifyResult(req)
+	notifyReq, err := wechat.ParseNotifyResult(req)
 	if err != nil {
 		fmt.Println("err:", err)
 	}
 	fmt.Println("notifyReq:", *notifyReq)
 
 	//验签
-	ok, err := gopay.VerifyWeChatSign("GFDS8j98rewnmgl45wHTt980jg543abc", gopay.SignType_MD5, notifyReq)
+	ok, err := wechat.VerifySign("GFDS8j98rewnmgl45wHTt980jg543abc", wechat.SignType_MD5, notifyReq)
 	if err != nil {
 		fmt.Println("err:", err)
 	}
@@ -203,13 +204,13 @@ func ParseWeChatNotifyResultAndVerifyWeChatSign(req *http.Request) string {
 
 	//或者
 
-	bodyMap, err := gopay.ParseWeChatNotifyResultToBodyMap(req)
+	bodyMap, err := wechat.ParseNotifyResultToBodyMap(req)
 	if err != nil {
 		fmt.Println("err:", err)
 	}
 	fmt.Println("bodyMap:", bodyMap)
 
-	ok, err = gopay.VerifyWeChatSign("GFDS8j98rewnmgl45wHTt980jg543abc", gopay.SignType_MD5, bodyMap)
+	ok, err = wechat.VerifySign("GFDS8j98rewnmgl45wHTt980jg543abc", wechat.SignType_MD5, bodyMap)
 	if err != nil {
 		fmt.Println("err:", err)
 	}
@@ -222,9 +223,9 @@ func ParseWeChatNotifyResultAndVerifyWeChatSign(req *http.Request) string {
 
 // 解析微信退款异步通知的参数,解析出来的 req_info 是加密数据,需解密
 func ParseWeChatRefundNotifyResult(req *http.Request) string {
-	rsp := new(gopay.WeChatNotifyResponse)
+	rsp := new(wechat.NotifyResponse)
 	// 解析参数
-	notifyReq, err := gopay.ParseWeChatRefundNotifyResult(req)
+	notifyReq, err := wechat.ParseRefundNotifyResult(req)
 	if err != nil {
 		fmt.Println("err:", err)
 	}
@@ -232,7 +233,7 @@ func ParseWeChatRefundNotifyResult(req *http.Request) string {
 	// 退款通知无sign,不用验签
 
 	// 解密退款异步通知的加密数据
-	refundNotify, err := gopay.DecryptRefundNotifyReqInfo(notifyReq.ReqInfo, "GFDS8j98rewnmgl45wHTt980jg543abc")
+	refundNotify, err := wechat.DecryptRefundNotifyReqInfo(notifyReq.ReqInfo, "GFDS8j98rewnmgl45wHTt980jg543abc")
 	if err != nil {
 		fmt.Println("err:", err)
 	}

+ 2 - 1
examples/wechat/wx_Transfer.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 
 	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/wechat"
 )
 
 func Transfer() {
@@ -12,7 +13,7 @@ func Transfer() {
 	//    MchID:商户ID
 	//    ApiKey:Key值
 	//    isProd:是否是正式环境(企业转账到个人账户,默认正式环境)
-	client := gopay.NewWeChatClient("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", false)
+	client := wechat.NewClient("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", false)
 
 	err := client.AddCertFilePath("iguiyu_cert/apiclient_cert.pem", "iguiyu_cert/apiclient_key.pem", "iguiyu_cert/apiclient_cert.p12")
 	if err != nil {

+ 8 - 7
examples/wechat/wx_UnifiedOrder.go

@@ -6,6 +6,7 @@ import (
 	"time"
 
 	"github.com/iGoogle-ink/gopay"
+	"github.com/iGoogle-ink/gopay/wechat"
 )
 
 func UnifiedOrder() {
@@ -14,10 +15,10 @@ func UnifiedOrder() {
 	//    mchId:商户ID
 	//    apiKey:API秘钥值
 	//    isProd:是否是正式环境
-	client := gopay.NewWeChatClient("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", false)
+	client := wechat.NewClient("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", false)
 
 	//设置国家
-	client.SetCountry(gopay.China)
+	client.SetCountry(wechat.China)
 
 	number := gopay.GetRandomString(32)
 	fmt.Println("out_trade_no:", number)
@@ -29,9 +30,9 @@ func UnifiedOrder() {
 	body.Set("total_fee", 1)
 	body.Set("spbill_create_ip", "127.0.0.1")
 	body.Set("notify_url", "http://www.gopay.ink")
-	body.Set("trade_type", gopay.TradeType_H5)
+	body.Set("trade_type", wechat.TradeType_H5)
 	body.Set("device_info", "WEB")
-	body.Set("sign_type", gopay.SignType_MD5)
+	body.Set("sign_type", wechat.SignType_MD5)
 
 	sceneInfo := make(map[string]map[string]string)
 	h5Info := make(map[string]string)
@@ -43,8 +44,8 @@ func UnifiedOrder() {
 
 	//body.Set("openid", "o0Df70H2Q0fY8JXh1aFPIRyOBgu8")
 
-	//sign := gopay.GetWeChatParamSign("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", body)
-	//sign, _ := gopay.GetWeChatSanBoxParamSign("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", body)
+	//sign := gopay.GetParamSign("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", body)
+	//sign, _ := gopay.GetSanBoxParamSign("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", body)
 	//body.Set("sign", sign)
 
 	//请求支付下单,成功后得到结果
@@ -65,7 +66,7 @@ func UnifiedOrder() {
 
 	//获取H5支付需要的paySign
 	pac := "prepay_id=" + wxRsp.PrepayId
-	paySign := gopay.GetH5PaySign("wxdaa2ab9ef87b5497", wxRsp.NonceStr, pac, gopay.SignType_MD5, timeStamp, "GFDS8j98rewnmgl45wHTt980jg543abc")
+	paySign := wechat.GetH5PaySign("wxdaa2ab9ef87b5497", wxRsp.NonceStr, pac, wechat.SignType_MD5, timeStamp, "GFDS8j98rewnmgl45wHTt980jg543abc")
 	fmt.Println("paySign:", paySign)
 
 	//获取小程序需要的paySign

+ 1 - 1
http_client.go

@@ -145,7 +145,7 @@ func (c *Client) EndBytes() (res *http.Response, bs []byte, errs []error) {
 	if len(c.Errors) > 0 {
 		return nil, nil, c.Errors
 	}
-	var reader = strings.NewReader(null)
+	var reader = strings.NewReader(NULL)
 
 	req, err := func() (*http.Request, error) {
 		c.mu.RLock()

+ 1 - 0
qq_client.go

@@ -0,0 +1 @@
+package gopay

+ 38 - 36
wechat_client.go → wechat/wechat_client.go

@@ -1,4 +1,4 @@
-package gopay
+package wechat
 
 import (
 	"crypto/tls"
@@ -7,9 +7,11 @@ import (
 	"fmt"
 	"strings"
 	"sync"
+
+	"github.com/iGoogle-ink/gopay"
 )
 
-type WeChatClient struct {
+type Client struct {
 	AppId      string
 	MchId      string
 	ApiKey     string
@@ -26,8 +28,8 @@ type WeChatClient struct {
 //    mchId:商户ID
 //    ApiKey:API秘钥值
 //    IsProd:是否是正式环境
-func NewWeChatClient(appId, mchId, apiKey string, isProd bool) (client *WeChatClient) {
-	return &WeChatClient{
+func NewClient(appId, mchId, apiKey string, isProd bool) (client *Client) {
+	return &Client{
 		AppId:  appId,
 		MchId:  mchId,
 		ApiKey: apiKey,
@@ -36,7 +38,7 @@ func NewWeChatClient(appId, mchId, apiKey string, isProd bool) (client *WeChatCl
 
 // 提交付款码支付
 //    文档地址:https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_10&index=1
-func (w *WeChatClient) Micropay(body BodyMap) (wxRsp *WeChatMicropayResponse, err error) {
+func (w *Client) Micropay(body gopay.BodyMap) (wxRsp *MicropayResponse, err error) {
 	var bs []byte
 	if w.IsProd {
 		bs, err = w.doWeChat(body, wxMicropay)
@@ -46,7 +48,7 @@ func (w *WeChatClient) Micropay(body BodyMap) (wxRsp *WeChatMicropayResponse, er
 	if err != nil {
 		return
 	}
-	wxRsp = new(WeChatMicropayResponse)
+	wxRsp = new(MicropayResponse)
 	if err = xml.Unmarshal(bs, wxRsp); err != nil {
 		return nil, fmt.Errorf("xml.Unmarshal:%s", err.Error())
 	}
@@ -55,7 +57,7 @@ func (w *WeChatClient) Micropay(body BodyMap) (wxRsp *WeChatMicropayResponse, er
 
 // 统一下单
 //    文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1
-func (w *WeChatClient) UnifiedOrder(body BodyMap) (wxRsp *WeChatUnifiedOrderResponse, err error) {
+func (w *Client) UnifiedOrder(body gopay.BodyMap) (wxRsp *UnifiedOrderResponse, err error) {
 	var bs []byte
 	if w.IsProd {
 		bs, err = w.doWeChat(body, wxUnifiedorder)
@@ -66,7 +68,7 @@ func (w *WeChatClient) UnifiedOrder(body BodyMap) (wxRsp *WeChatUnifiedOrderResp
 	if err != nil {
 		return
 	}
-	wxRsp = new(WeChatUnifiedOrderResponse)
+	wxRsp = new(UnifiedOrderResponse)
 	if err = xml.Unmarshal(bs, wxRsp); err != nil {
 		return nil, fmt.Errorf("xml.Unmarshal:%s", err.Error())
 	}
@@ -75,7 +77,7 @@ func (w *WeChatClient) UnifiedOrder(body BodyMap) (wxRsp *WeChatUnifiedOrderResp
 
 // 查询订单
 //    文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2
-func (w *WeChatClient) QueryOrder(body BodyMap) (wxRsp *WeChatQueryOrderResponse, err error) {
+func (w *Client) QueryOrder(body gopay.BodyMap) (wxRsp *QueryOrderResponse, err error) {
 	var bs []byte
 	if w.IsProd {
 		bs, err = w.doWeChat(body, wxOrderquery)
@@ -85,7 +87,7 @@ func (w *WeChatClient) QueryOrder(body BodyMap) (wxRsp *WeChatQueryOrderResponse
 	if err != nil {
 		return
 	}
-	wxRsp = new(WeChatQueryOrderResponse)
+	wxRsp = new(QueryOrderResponse)
 	if err = xml.Unmarshal(bs, wxRsp); err != nil {
 		return nil, fmt.Errorf("xml.Unmarshal:%s", err.Error())
 	}
@@ -94,7 +96,7 @@ func (w *WeChatClient) QueryOrder(body BodyMap) (wxRsp *WeChatQueryOrderResponse
 
 // 关闭订单
 //    文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_3
-func (w *WeChatClient) CloseOrder(body BodyMap) (wxRsp *WeChatCloseOrderResponse, err error) {
+func (w *Client) CloseOrder(body gopay.BodyMap) (wxRsp *CloseOrderResponse, err error) {
 	var bs []byte
 	if w.IsProd {
 		bs, err = w.doWeChat(body, wxCloseorder)
@@ -104,7 +106,7 @@ func (w *WeChatClient) CloseOrder(body BodyMap) (wxRsp *WeChatCloseOrderResponse
 	if err != nil {
 		return
 	}
-	wxRsp = new(WeChatCloseOrderResponse)
+	wxRsp = new(CloseOrderResponse)
 	if err = xml.Unmarshal(bs, wxRsp); err != nil {
 		return nil, fmt.Errorf("xml.Unmarshal:%s", err.Error())
 	}
@@ -114,7 +116,7 @@ func (w *WeChatClient) CloseOrder(body BodyMap) (wxRsp *WeChatCloseOrderResponse
 // 撤销订单
 //    注意:如已使用client.AddCertFilePath()或client.AddCertFileByte()添加过证书,参数certFilePath、keyFilePath、pkcs12FilePath全传空字符串 "",如方法需单独使用证书,则传证书Path
 //    文档地址:https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_11&index=3
-func (w *WeChatClient) Reverse(body BodyMap, certFilePath, keyFilePath, pkcs12FilePath string) (wxRsp *WeChatReverseResponse, err error) {
+func (w *Client) Reverse(body gopay.BodyMap, certFilePath, keyFilePath, pkcs12FilePath string) (wxRsp *ReverseResponse, err error) {
 	var (
 		bs        []byte
 		tlsConfig *tls.Config
@@ -130,7 +132,7 @@ func (w *WeChatClient) Reverse(body BodyMap, certFilePath, keyFilePath, pkcs12Fi
 	if err != nil {
 		return
 	}
-	wxRsp = new(WeChatReverseResponse)
+	wxRsp = new(ReverseResponse)
 	if err = xml.Unmarshal(bs, wxRsp); err != nil {
 		return nil, fmt.Errorf("xml.Unmarshal:%s", err.Error())
 	}
@@ -140,7 +142,7 @@ func (w *WeChatClient) Reverse(body BodyMap, certFilePath, keyFilePath, pkcs12Fi
 // 申请退款
 //    注意:如已使用client.AddCertFilePath()或client.AddCertFileByte()添加过证书,参数certFilePath、keyFilePath、pkcs12FilePath全传空字符串 "",如方法需单独使用证书,则传证书Path
 //    文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_4
-func (w *WeChatClient) Refund(body BodyMap, certFilePath, keyFilePath, pkcs12FilePath string) (wxRsp *WeChatRefundResponse, err error) {
+func (w *Client) Refund(body gopay.BodyMap, certFilePath, keyFilePath, pkcs12FilePath string) (wxRsp *RefundResponse, err error) {
 	var (
 		bs        []byte
 		tlsConfig *tls.Config
@@ -156,7 +158,7 @@ func (w *WeChatClient) Refund(body BodyMap, certFilePath, keyFilePath, pkcs12Fil
 	if err != nil {
 		return
 	}
-	wxRsp = new(WeChatRefundResponse)
+	wxRsp = new(RefundResponse)
 	if err = xml.Unmarshal(bs, wxRsp); err != nil {
 		return nil, fmt.Errorf("xml.Unmarshal:%s", err.Error())
 	}
@@ -165,7 +167,7 @@ func (w *WeChatClient) Refund(body BodyMap, certFilePath, keyFilePath, pkcs12Fil
 
 // 查询退款
 //    文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_5
-func (w *WeChatClient) QueryRefund(body BodyMap) (wxRsp *WeChatQueryRefundResponse, err error) {
+func (w *Client) QueryRefund(body gopay.BodyMap) (wxRsp *QueryRefundResponse, err error) {
 	var bs []byte
 	if w.IsProd {
 		bs, err = w.doWeChat(body, wxRefundquery)
@@ -175,7 +177,7 @@ func (w *WeChatClient) QueryRefund(body BodyMap) (wxRsp *WeChatQueryRefundRespon
 	if err != nil {
 		return
 	}
-	wxRsp = new(WeChatQueryRefundResponse)
+	wxRsp = new(QueryRefundResponse)
 	if err = xml.Unmarshal(bs, wxRsp); err != nil {
 		return nil, fmt.Errorf("xml.Unmarshal:%s", err.Error())
 	}
@@ -184,7 +186,7 @@ func (w *WeChatClient) QueryRefund(body BodyMap) (wxRsp *WeChatQueryRefundRespon
 
 // 下载对账单
 //    文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_6
-func (w *WeChatClient) DownloadBill(body BodyMap) (wxRsp string, err error) {
+func (w *Client) DownloadBill(body gopay.BodyMap) (wxRsp string, err error) {
 	var bs []byte
 	if w.IsProd {
 		bs, err = w.doWeChat(body, wxDownloadbill)
@@ -202,14 +204,14 @@ func (w *WeChatClient) DownloadBill(body BodyMap) (wxRsp string, err error) {
 //    注意:如已使用client.AddCertFilePath()或client.AddCertFileByte()添加过证书,参数certFilePath、keyFilePath、pkcs12FilePath全传空字符串 "",如方法需单独使用证书,则传证书Path
 //    貌似不支持沙箱环境,因为沙箱环境默认需要用MD5签名,但是此接口仅支持HMAC-SHA256签名
 //    文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_18&index=7
-func (w *WeChatClient) DownloadFundFlow(body BodyMap, certFilePath, keyFilePath, pkcs12FilePath string) (wxRsp string, err error) {
+func (w *Client) DownloadFundFlow(body gopay.BodyMap, certFilePath, keyFilePath, pkcs12FilePath string) (wxRsp string, err error) {
 	var (
 		bs        []byte
 		tlsConfig *tls.Config
 	)
 	if w.IsProd {
 		if tlsConfig, err = w.addCertConfig(certFilePath, keyFilePath, pkcs12FilePath); err != nil {
-			return null, err
+			return gopay.NULL, err
 		}
 		bs, err = w.doWeChat(body, wxDownloadfundflow, tlsConfig)
 	} else {
@@ -226,7 +228,7 @@ func (w *WeChatClient) DownloadFundFlow(body BodyMap, certFilePath, keyFilePath,
 //    注意:如已使用client.AddCertFilePath()或client.AddCertFileByte()添加过证书,参数certFilePath、keyFilePath、pkcs12FilePath全传空字符串 "",如方法需单独使用证书,则传证书Path
 //    貌似不支持沙箱环境,因为沙箱环境默认需要用MD5签名,但是此接口仅支持HMAC-SHA256签名
 //    文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_17&index=11
-func (w *WeChatClient) BatchQueryComment(body BodyMap, certFilePath, keyFilePath, pkcs12FilePath string) (wxRsp string, err error) {
+func (w *Client) BatchQueryComment(body gopay.BodyMap, certFilePath, keyFilePath, pkcs12FilePath string) (wxRsp string, err error) {
 	var (
 		bs        []byte
 		tlsConfig *tls.Config
@@ -234,7 +236,7 @@ func (w *WeChatClient) BatchQueryComment(body BodyMap, certFilePath, keyFilePath
 	if w.IsProd {
 		body.Set("sign_type", SignType_HMAC_SHA256)
 		if tlsConfig, err = w.addCertConfig(certFilePath, keyFilePath, pkcs12FilePath); err != nil {
-			return null, err
+			return gopay.NULL, err
 		}
 		bs, err = w.doWeChat(body, wxBatchquerycomment, tlsConfig)
 	} else {
@@ -251,7 +253,7 @@ func (w *WeChatClient) BatchQueryComment(body BodyMap, certFilePath, keyFilePath
 //    注意:如已使用client.AddCertFilePath()或client.AddCertFileByte()添加过证书,参数certFilePath、keyFilePath、pkcs12FilePath全传空字符串 "",如方法需单独使用证书,则传证书Path
 //    注意:此方法未支持沙箱环境,默认正式环境,转账请慎重
 //    文档地址:https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_1
-func (w *WeChatClient) Transfer(body BodyMap, certFilePath, keyFilePath, pkcs12FilePath string) (wxRsp *WeChatTransfersResponse, err error) {
+func (w *Client) Transfer(body gopay.BodyMap, certFilePath, keyFilePath, pkcs12FilePath string) (wxRsp *TransfersResponse, err error) {
 	body.Set("mch_appid", w.AppId)
 	body.Set("mchid", w.MchId)
 	var (
@@ -261,15 +263,15 @@ func (w *WeChatClient) Transfer(body BodyMap, certFilePath, keyFilePath, pkcs12F
 	if tlsConfig, err = w.addCertConfig(certFilePath, keyFilePath, pkcs12FilePath); err != nil {
 		return nil, err
 	}
-	body.Set("sign", getWeChatReleaseSign(w.ApiKey, SignType_MD5, body))
+	body.Set("sign", getReleaseSign(w.ApiKey, SignType_MD5, body))
 
-	httpClient := NewHttpClient().SetTLSConfig(tlsConfig).Type(TypeXML)
-	if w.BaseURL != null {
+	httpClient := gopay.NewHttpClient().SetTLSConfig(tlsConfig).Type(gopay.TypeXML)
+	if w.BaseURL != gopay.NULL {
 		w.mu.RLock()
 		url = w.BaseURL + wxTransfers
 		w.mu.RUnlock()
 	}
-	wxRsp = new(WeChatTransfersResponse)
+	wxRsp = new(TransfersResponse)
 	res, errs := httpClient.Post(url).SendString(generateXml(body)).EndStruct(wxRsp)
 	if len(errs) > 0 {
 		return nil, errs[0]
@@ -282,46 +284,46 @@ func (w *WeChatClient) Transfer(body BodyMap, certFilePath, keyFilePath, pkcs12F
 
 // 公众号纯签约(未完成)
 //    文档地址:https://pay.weixin.qq.com/wiki/doc/api/pap.php?chapter=18_1&index=1
-func (w *WeChatClient) EntrustPublic(body BodyMap) (bs []byte, err error) {
+func (w *Client) EntrustPublic(body gopay.BodyMap) (bs []byte, err error) {
 	bs, err = w.doWeChat(body, wxEntrustPublic)
 
 	return nil, nil
 }
 
 // 向微信发送请求
-func (w *WeChatClient) doWeChat(body BodyMap, path string, tlsConfig ...*tls.Config) (bs []byte, err error) {
+func (w *Client) doWeChat(body gopay.BodyMap, path string, tlsConfig ...*tls.Config) (bs []byte, err error) {
 	body.Set("appid", w.AppId)
 	body.Set("mch_id", w.MchId)
 	var (
 		sign string
 		url  = wxBaseUrlCh + path
 	)
-	if body.Get("sign") != null {
+	if body.Get("sign") != gopay.NULL {
 		goto GoRequest
 	}
 	if !w.IsProd {
 		body.Set("sign_type", SignType_MD5)
-		if sign, err = getWeChatSignBoxSign(w.MchId, w.ApiKey, body); err != nil {
+		if sign, err = getSignBoxSign(w.MchId, w.ApiKey, body); err != nil {
 			return nil, err
 		}
 	} else {
-		sign = getWeChatReleaseSign(w.ApiKey, body.Get("sign_type"), body)
+		sign = getReleaseSign(w.ApiKey, body.Get("sign_type"), body)
 	}
 	body.Set("sign", sign)
 
 GoRequest:
-	httpClient := NewHttpClient()
+	httpClient := gopay.NewHttpClient()
 	if w.IsProd && tlsConfig != nil {
 		httpClient.SetTLSConfig(tlsConfig[0])
 	}
 
-	if w.BaseURL != null {
+	if w.BaseURL != gopay.NULL {
 		w.mu.RLock()
 		url = w.BaseURL + path
 		w.mu.RUnlock()
 	}
 
-	res, bs, errs := httpClient.Type(TypeXML).Post(url).SendString(generateXml(body)).EndBytes()
+	res, bs, errs := httpClient.Type(gopay.TypeXML).Post(url).SendString(generateXml(body)).EndBytes()
 	if len(errs) > 0 {
 		return nil, errs[0]
 	}

+ 34 - 27
wechat_client_test.go → wechat/wechat_client_test.go

@@ -1,39 +1,46 @@
-package gopay
+package wechat
 
 import (
-	"encoding/json"
+	"encoding/xml"
 	"fmt"
 	"testing"
+
+	"github.com/iGoogle-ink/gopay"
 )
 
 type Student struct {
-	Name  string `json:"name,omitempty"`
-	Age   int    `json:"age,omitempty"`
-	Sign  string `json:"sign,omitempty"`
-	Phone string `json:"phone,omitempty"`
+	XMLName xml.Name `xml:"xml"`
+	Name    string   `xml:"name,omitempty"`
+	Age     int      `xml:"age,omitempty"`
+	Sign    string   `xml:"sign,omitempty"`
+	Phone   string   `xml:"phone,omitempty"`
 }
 
 func TestBodyMap_MarshalXML(t *testing.T) {
 
-	student := new(Student)
-	student.Name = "Jerry"
-	student.Age = 28
-	student.Phone = "18017448610"
+	//student := new(Student)
+	//student.Name = "Jerry"
+	//student.Age = 28
+	//student.Phone = "18017448610"
+	student := make(gopay.BodyMap)
+	student.Set("name", "Jerry")
+	student.Set("age", 28)
+	student.Set("phone", "18017448610")
 
-	marshal, err := json.Marshal(student)
+	marshal, err := xml.Marshal(student)
 	if err != nil {
 		fmt.Println("err:", err)
 	}
 
 	fmt.Println("marshal:", string(marshal))
 
-	maps := make(map[string]interface{})
+	bm := make(gopay.BodyMap)
 
-	err = json.Unmarshal(marshal, &maps)
+	err = xml.Unmarshal(marshal, &bm)
 	if err != nil {
 		fmt.Println("err2:", err)
 	}
-	fmt.Println("maps:", maps)
+	fmt.Println("bm:", bm)
 
 	//maps := make(BodyMap)
 	//maps.Set("name", "jerry")
@@ -47,20 +54,20 @@ func TestBodyMap_MarshalXML(t *testing.T) {
 	//fmt.Println("ssss:", string(bytes))
 }
 
-func TestVerifyWeChatResponseSign(t *testing.T) {
+func TestVerifySign(t *testing.T) {
 	student := new(Student)
 	student.Name = "Jerry"
 	student.Age = 1
 	student.Sign = "544E55ED43B787B945FF0BF8344A4D69"
 	student.Phone = "18017448610"
 
-	maps := make(BodyMap)
+	maps := make(gopay.BodyMap)
 	maps["name"] = "Jerry"
 	maps["age"] = 1
 	maps["sign"] = "544E55ED43B787B945FF0BF8344A4D69"
 	maps["phone"] = "18017448610"
 
-	ok, err := VerifyWeChatSign("ABCDEFG", "MD5", student)
+	ok, err := VerifySign("ABCDEFG", "MD5", student)
 	if err != nil {
 		fmt.Println("errrrr:", err)
 		return
@@ -68,17 +75,17 @@ func TestVerifyWeChatResponseSign(t *testing.T) {
 	fmt.Println("ok:", ok)
 }
 
-func TestDecryptWeChatOpenDataToStruct(t *testing.T) {
+func TestDecryptOpenDataToStruct(t *testing.T) {
 	data := "Kf3TdPbzEmhWMuPKtlKxIWDkijhn402w1bxoHL4kLdcKr6jT1jNcIhvDJfjXmJcgDWLjmBiIGJ5acUuSvxLws3WgAkERmtTuiCG10CKLsJiR+AXVk7B2TUQzsq88YVilDz/YAN3647REE7glGmeBPfvUmdbfDzhL9BzvEiuRhABuCYyTMz4iaM8hFjbLB1caaeoOlykYAFMWC5pZi9P8uw=="
 	iv := "Cds8j3VYoGvnTp1BrjXdJg=="
 	session := "lyY4HPQbaOYzZdG+JcYK9w=="
-	phone := new(WeChatUserPhone)
+	phone := new(UserPhone)
 	//解密开放数据
 	//    encryptedData:包括敏感数据在内的完整用户信息的加密数据
 	//    iv:加密算法的初始向量
 	//    sessionKey:会话密钥
 	//    beanPtr:需要解析到的结构体指针
-	err := DecryptWeChatOpenDataToStruct(data, iv, session, phone)
+	err := DecryptOpenDataToStruct(data, iv, session, phone)
 	if err != nil {
 		fmt.Println("err:", err)
 		return
@@ -93,9 +100,9 @@ func TestDecryptWeChatOpenDataToStruct(t *testing.T) {
 	iv2 := "r7BXXKkLb8qrSNn05n0qiA=="
 
 	//微信小程序 用户信息
-	userInfo := new(WeChatAppletUserInfo)
+	userInfo := new(AppletUserInfo)
 
-	err = DecryptWeChatOpenDataToStruct(encryptedData, iv2, sessionKey, userInfo)
+	err = DecryptOpenDataToStruct(encryptedData, iv2, sessionKey, userInfo)
 	if err != nil {
 		fmt.Println("err:", err)
 		return
@@ -111,7 +118,7 @@ func TestDecryptWeChatOpenDataToStruct(t *testing.T) {
 	fmt.Println("Watermark:", userInfo.Watermark)
 }
 
-func TestDecryptWeChatOpenDataToBodyMap(t *testing.T) {
+func TestDecryptOpenDataToBodyMap(t *testing.T) {
 	data := "Kf3TdPbzEmhWMuPKtlKxIWDkijhn402w1bxoHL4kLdcKr6jT1jNcIhvDJfjXmJcgDWLjmBiIGJ5acUuSvxLws3WgAkERmtTuiCG10CKLsJiR+AXVk7B2TUQzsq88YVilDz/YAN3647REE7glGmeBPfvUmdbfDzhL9BzvEiuRhABuCYyTMz4iaM8hFjbLB1caaeoOlykYAFMWC5pZi9P8uw=="
 	iv := "Cds8j3VYoGvnTp1BrjXdJg=="
 	session := "lyY4HPQbaOYzZdG+JcYK9w=="
@@ -120,7 +127,7 @@ func TestDecryptWeChatOpenDataToBodyMap(t *testing.T) {
 	//    encryptedData:包括敏感数据在内的完整用户信息的加密数据
 	//    iv:加密算法的初始向量
 	//    sessionKey:会话密钥
-	bm, err := DecryptWeChatOpenDataToBodyMap(data, iv, session)
+	bm, err := DecryptOpenDataToBodyMap(data, iv, session)
 	if err != nil {
 		fmt.Println("err:", err)
 		return
@@ -140,7 +147,7 @@ func TestDecryptRefundNotifyReqInfo(t *testing.T) {
 }
 
 func TestBodyMap_Set_Get(t *testing.T) {
-	bm := make(BodyMap)
+	bm := make(gopay.BodyMap)
 	sceneInfo := make(map[string]map[string]string)
 	h5Info := make(map[string]string)
 	h5Info["type"] = "Wap"
@@ -161,8 +168,8 @@ func TestBodyMap_Set_Get(t *testing.T) {
 
 }
 
-func TestGetWeChatAppletAccessToken(t *testing.T) {
-	token, err := GetWeChatAppletAccessToken("wxdaa2ab9ef87b5497", "AppSecret")
+func TestGetAppletAccessToken(t *testing.T) {
+	token, err := GetAppletAccessToken("wxdaa2ab9ef87b5497", "AppSecret")
 	if err != nil {
 		fmt.Println(err)
 		return

+ 74 - 16
wechat_rsp.go → wechat/wechat_model.go

@@ -1,6 +1,64 @@
-package gopay
+package wechat
 
-type WeChatUnifiedOrderResponse struct {
+const (
+	// 境外国家地区
+	China         Country = 1 // 中国国内
+	China2        Country = 2 // 中国国内(冗灾方案)
+	SoutheastAsia Country = 3 // 东南亚
+	Other         Country = 4 // 其他国家
+
+	// URL
+	wxBaseUrlCh  = "https://api.mch.weixin.qq.com/"   //中国国内
+	wxBaseUrlCh2 = "https://api2.mch.weixin.qq.com/"  //中国国内
+	wxBaseUrlHk  = "https://apihk.mch.weixin.qq.com/" //东南亚
+	wxBaseUrlUs  = "https://apius.mch.weixin.qq.com/" //其他
+
+	// 正式
+	wxMicropay          = "pay/micropay"                          //提交付款码支付
+	wxUnifiedorder      = "pay/unifiedorder"                      //统一下单
+	wxOrderquery        = "pay/orderquery"                        //查询订单
+	wxCloseorder        = "pay/closeorder"                        //关闭订单
+	wxRefund            = "secapi/pay/refund"                     //申请退款
+	wxReverse           = "secapi/pay/reverse"                    //撤销订单
+	wxRefundquery       = "pay/refundquery"                       //查询退款
+	wxDownloadbill      = "pay/downloadbill"                      //下载对账单
+	wxDownloadfundflow  = "pay/downloadfundflow"                  //下载资金账单
+	wxBatchquerycomment = "billcommentsp/batchquerycomment"       //拉取订单评价数据
+	wxTransfers         = "mmpaymkttransfers/promotion/transfers" //企业向微信用户个人付款
+	wxEntrustPublic     = "papay/entrustweb"                      //公众号纯签约
+	wxEntrustApp        = "papay/preentrustweb"                   //APP纯签约
+	wxEntrustH5         = "papay/h5entrustweb"                    //H5纯签约
+	wxEntrustQuery      = "papay/querycontract"                   //查询签约关系
+	wxEntrustDelete     = "papay/deletecontract"                  //申请解约
+	wxEntrustApplyPay   = "pay/pappayapply"                       //申请扣款
+	wxEntrustQueryOrder = "pay/paporderquery"                     //查询扣款订单
+
+	// SanBox
+	wxSandboxGetsignkey        = "https://api.mch.weixin.qq.com/sandboxnew/pay/getsignkey"
+	wxSandboxMicropay          = "sandboxnew/pay/micropay"
+	wxSandboxUnifiedorder      = "sandboxnew/pay/unifiedorder"
+	wxSandboxOrderquery        = "sandboxnew/pay/orderquery"
+	wxSandboxCloseorder        = "sandboxnew/pay/closeorder"
+	wxSandboxRefund            = "sandboxnew/pay/refund"
+	wxSandboxReverse           = "sandboxnew/pay/reverse"
+	wxSandboxRefundquery       = "sandboxnew/pay/refundquery"
+	wxSandboxDownloadbill      = "sandboxnew/pay/downloadbill"
+	wxSandboxDownloadfundflow  = "sandboxnew/pay/downloadfundflow"
+	wxSandboxBatchquerycomment = "sandboxnew/billcommentsp/batchquerycomment"
+
+	// 支付类型
+	TradeType_Mini   = "JSAPI"
+	TradeType_JsApi  = "JSAPI"
+	TradeType_App    = "APP"
+	TradeType_H5     = "MWEB"
+	TradeType_Native = "NATIVE"
+
+	// 签名方式
+	SignType_MD5         = "MD5"
+	SignType_HMAC_SHA256 = "HMAC-SHA256"
+)
+
+type UnifiedOrderResponse struct {
 	ReturnCode string `xml:"return_code,omitempty" json:"return_code,omitempty"`
 	ReturnMsg  string `xml:"return_msg,omitempty" json:"return_msg,omitempty"`
 	Appid      string `xml:"appid,omitempty" json:"appid,omitempty"`
@@ -17,7 +75,7 @@ type WeChatUnifiedOrderResponse struct {
 	MwebUrl    string `xml:"mweb_url,omitempty" json:"mweb_url,omitempty"`
 }
 
-type WeChatQueryOrderResponse struct {
+type QueryOrderResponse struct {
 	ReturnCode         string `xml:"return_code,omitempty" json:"return_code,omitempty"`
 	ReturnMsg          string `xml:"return_msg,omitempty" json:"return_msg,omitempty"`
 	Appid              string `xml:"appid,omitempty" json:"appid,omitempty"`
@@ -53,7 +111,7 @@ type WeChatQueryOrderResponse struct {
 	TradeStateDesc     string `xml:"trade_state_desc,omitempty" json:"trade_state_desc,omitempty"`
 }
 
-type WeChatCloseOrderResponse struct {
+type CloseOrderResponse struct {
 	ReturnCode string `xml:"return_code,omitempty" json:"return_code,omitempty"`
 	ReturnMsg  string `xml:"return_msg,omitempty" json:"return_msg,omitempty"`
 	Appid      string `xml:"appid,omitempty" json:"appid,omitempty"`
@@ -66,7 +124,7 @@ type WeChatCloseOrderResponse struct {
 	ErrCodeDes string `xml:"err_code_des,omitempty" json:"err_code_des,omitempty"`
 }
 
-type WeChatReverseResponse struct {
+type ReverseResponse struct {
 	ReturnCode string `xml:"return_code,omitempty" json:"return_code,omitempty"`
 	ReturnMsg  string `xml:"return_msg,omitempty" json:"return_msg,omitempty"`
 	Appid      string `xml:"appid,omitempty" json:"appid,omitempty"`
@@ -79,7 +137,7 @@ type WeChatReverseResponse struct {
 	Recall     string `xml:"recall,omitempty" json:"recall,omitempty"`
 }
 
-type WeChatRefundResponse struct {
+type RefundResponse struct {
 	ReturnCode          string `xml:"return_code,omitempty" json:"return_code,omitempty"`
 	ReturnMsg           string `xml:"return_msg,omitempty" json:"return_msg,omitempty"`
 	ResultCode          string `xml:"result_code,omitempty" json:"result_code,omitempty"`
@@ -111,7 +169,7 @@ type WeChatRefundResponse struct {
 	CouponRefundId1     string `xml:"coupon_refund_id_1,omitempty" json:"coupon_refund_id_1,omitempty"`
 }
 
-type WeChatQueryRefundResponse struct {
+type QueryRefundResponse struct {
 	ReturnCode           string `xml:"return_code,omitempty" json:"return_code,omitempty"`
 	ReturnMsg            string `xml:"return_msg,omitempty" json:"return_msg,omitempty"`
 	ResultCode           string `xml:"result_code,omitempty" json:"result_code,omitempty"`
@@ -166,7 +224,7 @@ type WeChatQueryRefundResponse struct {
 	RefundSuccessTime1   string `xml:"refund_success_time_1,omitempty" json:"refund_success_time_1,omitempty"`
 }
 
-type WeChatMicropayResponse struct {
+type MicropayResponse struct {
 	ReturnCode         string `xml:"return_code,omitempty" json:"return_code,omitempty"`
 	ReturnMsg          string `xml:"return_msg,omitempty" json:"return_msg,omitempty"`
 	Appid              string `xml:"appid,omitempty" json:"appid,omitempty"`
@@ -194,7 +252,7 @@ type WeChatMicropayResponse struct {
 	PromotionDetail    string `xml:"promotion_detail,omitempty" json:"promotion_detail,omitempty"`
 }
 
-type WeChatTransfersResponse struct {
+type TransfersResponse struct {
 	ReturnCode     string `xml:"return_code,omitempty" json:"return_code,omitempty"`
 	ReturnMsg      string `xml:"return_msg,omitempty" json:"return_msg,omitempty"`
 	MchAppid       string `xml:"mch_appid,omitempty" json:"mch_appid,omitempty"`
@@ -216,7 +274,7 @@ type getSignKeyResponse struct {
 	SandboxSignkey string `xml:"sandbox_signkey,omitempty" json:"sandbox_signkey,omitempty"`
 }
 
-type WeChatNotifyRequest struct {
+type NotifyRequest struct {
 	ReturnCode         string `xml:"return_code,omitempty" json:"return_code,omitempty"`
 	ReturnMsg          string `xml:"return_msg,omitempty" json:"return_msg,omitempty"`
 	ResultCode         string `xml:"result_code,omitempty" json:"result_code,omitempty"`
@@ -251,7 +309,7 @@ type WeChatNotifyRequest struct {
 	TimeEnd            string `xml:"time_end,omitempty" json:"time_end,omitempty"`
 }
 
-type WeChatRefundNotifyRequest struct {
+type RefundNotifyRequest struct {
 	ReturnCode string `xml:"return_code,omitempty" json:"return_code,omitempty"`
 	ReturnMsg  string `xml:"return_msg,omitempty" json:"return_msg,omitempty"`
 	Appid      string `xml:"appid,omitempty" json:"appid,omitempty"`
@@ -298,7 +356,7 @@ type AccessToken struct {
 	Errmsg      string `json:"errmsg,omitempty"`       // 错误信息
 }
 
-type WeChatUserInfo struct {
+type UserInfo struct {
 	Subscribe      int    `json:"subscribe,omitempty"`       // 用户是否订阅该公众号标识,值为0时,代表此用户没有关注该公众号,拉取不到其余信息。
 	Openid         string `json:"openid,omitempty"`          // 用户唯一标识
 	Nickname       string `json:"nickname,omitempty"`        // 用户的昵称
@@ -321,7 +379,7 @@ type WeChatUserInfo struct {
 }
 
 // 微信小程序解密后 用户手机号结构体
-type WeChatUserPhone struct {
+type UserPhone struct {
 	PhoneNumber     string         `json:"phoneNumber,omitempty"`
 	PurePhoneNumber string         `json:"purePhoneNumber,omitempty"`
 	CountryCode     string         `json:"countryCode,omitempty"`
@@ -329,7 +387,7 @@ type WeChatUserPhone struct {
 }
 
 // 微信小程序解密后 用户信息结构体
-type WeChatAppletUserInfo struct {
+type AppletUserInfo struct {
 	OpenId    string         `json:"openId,omitempty"`
 	NickName  string         `json:"nickName,omitempty"`
 	Gender    int            `json:"gender,omitempty"`
@@ -360,7 +418,7 @@ type OpenIdByAuthCodeRsp struct {
 }
 
 // App应用微信第三方登录,code换取access_token
-type AppWeChatLoginAccessToken struct {
+type AppLoginAccessToken struct {
 	AccessToken  string `json:"access_token,omitempty"`
 	ExpiresIn    int    `json:"expires_in,omitempty"`
 	Openid       string `json:"openid,omitempty"`
@@ -372,7 +430,7 @@ type AppWeChatLoginAccessToken struct {
 }
 
 // 刷新App应用微信第三方登录后,获取的 access_token
-type RefreshAppWeChatLoginAccessTokenRsp struct {
+type RefreshAppLoginAccessTokenRsp struct {
 	AccessToken  string `json:"access_token,omitempty"`
 	ExpiresIn    int    `json:"expires_in,omitempty"`
 	Openid       string `json:"openid,omitempty"`

+ 20 - 18
wechat_params.go → wechat/wechat_params.go

@@ -1,4 +1,4 @@
-package gopay
+package wechat
 
 import (
 	"crypto/hmac"
@@ -13,6 +13,8 @@ import (
 	"hash"
 	"io/ioutil"
 	"strings"
+
+	"github.com/iGoogle-ink/gopay"
 )
 
 type Country int
@@ -20,7 +22,7 @@ type Country int
 // 设置支付国家(默认:中国国内)
 //    根据支付地区情况设置国家
 //    country:<China:中国国内,China2:中国国内(冗灾方案),SoutheastAsia:东南亚,Other:其他国家>
-func (w *WeChatClient) SetCountry(country Country) (client *WeChatClient) {
+func (w *Client) SetCountry(country Country) (client *Client) {
 	w.mu.Lock()
 	switch country {
 	case China:
@@ -42,7 +44,7 @@ func (w *WeChatClient) SetCountry(country Country) (client *WeChatClient) {
 //    certFile:apiclient_cert.pem byte数组
 //    keyFile:apiclient_key.pem byte数组
 //    pkcs12File:apiclient_cert.p12 byte数组
-func (w *WeChatClient) AddCertFileByte(certFile, keyFile, pkcs12File []byte) {
+func (w *Client) AddCertFileByte(certFile, keyFile, pkcs12File []byte) {
 	w.mu.Lock()
 	w.CertFile = certFile
 	w.KeyFile = keyFile
@@ -55,7 +57,7 @@ func (w *WeChatClient) AddCertFileByte(certFile, keyFile, pkcs12File []byte) {
 //    keyFilePath:apiclient_key.pem 路径
 //    pkcs12FilePath:apiclient_cert.p12 路径
 //    返回err
-func (w *WeChatClient) AddCertFilePath(certFilePath, keyFilePath, pkcs12FilePath string) (err error) {
+func (w *Client) AddCertFilePath(certFilePath, keyFilePath, pkcs12FilePath string) (err error) {
 	var (
 		cert, key, pkcs []byte
 	)
@@ -76,14 +78,14 @@ func (w *WeChatClient) AddCertFilePath(certFilePath, keyFilePath, pkcs12FilePath
 	return
 }
 
-func (w *WeChatClient) addCertConfig(certFilePath, keyFilePath, pkcs12FilePath string) (tlsConfig *tls.Config, err error) {
+func (w *Client) addCertConfig(certFilePath, keyFilePath, pkcs12FilePath string) (tlsConfig *tls.Config, err error) {
 	var (
 		pkcs        []byte
 		certificate tls.Certificate
 		pkcsPool    = x509.NewCertPool()
 	)
 
-	if certFilePath == null && keyFilePath == null && pkcs12FilePath == null {
+	if certFilePath == gopay.NULL && keyFilePath == gopay.NULL && pkcs12FilePath == gopay.NULL {
 		w.mu.RLock()
 		pkcsPool.AppendCertsFromPEM(w.Pkcs12File)
 		certificate, err = tls.X509KeyPair(w.CertFile, w.KeyFile)
@@ -98,7 +100,7 @@ func (w *WeChatClient) addCertConfig(certFilePath, keyFilePath, pkcs12FilePath s
 		return tlsConfig, nil
 	}
 
-	if certFilePath != null && keyFilePath != null && pkcs12FilePath != null {
+	if certFilePath != gopay.NULL && keyFilePath != gopay.NULL && pkcs12FilePath != gopay.NULL {
 		if pkcs, err = ioutil.ReadFile(pkcs12FilePath); err != nil {
 			return nil, fmt.Errorf("ioutil.ReadFile:%s", err.Error())
 		}
@@ -117,7 +119,7 @@ func (w *WeChatClient) addCertConfig(certFilePath, keyFilePath, pkcs12FilePath s
 }
 
 // 获取微信支付正式环境Sign值
-func getWeChatReleaseSign(apiKey string, signType string, bm BodyMap) (sign string) {
+func getReleaseSign(apiKey string, signType string, bm gopay.BodyMap) (sign string) {
 	var h hash.Hash
 	if signType == SignType_HMAC_SHA256 {
 		h = hmac.New(sha256.New, []byte(apiKey))
@@ -130,12 +132,12 @@ func getWeChatReleaseSign(apiKey string, signType string, bm BodyMap) (sign stri
 }
 
 // 获取微信支付沙箱环境Sign值
-func getWeChatSignBoxSign(mchId, apiKey string, bm BodyMap) (sign string, err error) {
+func getSignBoxSign(mchId, apiKey string, bm gopay.BodyMap) (sign string, err error) {
 	var (
 		sandBoxApiKey string
 		h             hash.Hash
 	)
-	if sandBoxApiKey, err = getSanBoxKey(mchId, GetRandomString(32), apiKey, SignType_MD5); err != nil {
+	if sandBoxApiKey, err = getSanBoxKey(mchId, gopay.GetRandomString(32), apiKey, SignType_MD5); err != nil {
 		return
 	}
 	h = md5.New()
@@ -146,11 +148,11 @@ func getWeChatSignBoxSign(mchId, apiKey string, bm BodyMap) (sign string, err er
 
 // 从微信提供的接口获取:SandboxSignKey
 func getSanBoxKey(mchId, nonceStr, apiKey, signType string) (key string, err error) {
-	bm := make(BodyMap)
+	bm := make(gopay.BodyMap)
 	bm.Set("mch_id", mchId)
 	bm.Set("nonce_str", nonceStr)
 	//沙箱环境:获取沙箱环境ApiKey
-	if key, err = getSanBoxSignKey(mchId, nonceStr, getWeChatReleaseSign(apiKey, signType, bm)); err != nil {
+	if key, err = getSanBoxSignKey(mchId, nonceStr, getReleaseSign(apiKey, signType, bm)); err != nil {
 		return
 	}
 	return
@@ -158,27 +160,27 @@ func getSanBoxKey(mchId, nonceStr, apiKey, signType string) (key string, err err
 
 // 从微信提供的接口获取:SandboxSignKey
 func getSanBoxSignKey(mchId, nonceStr, sign string) (key string, err error) {
-	reqs := make(BodyMap)
+	reqs := make(gopay.BodyMap)
 	reqs.Set("mch_id", mchId)
 	reqs.Set("nonce_str", nonceStr)
 	reqs.Set("sign", sign)
 
 	keyResponse := new(getSignKeyResponse)
-	_, errs := NewHttpClient().Type(TypeXML).Post(wxSandboxGetsignkey).SendString(generateXml(reqs)).EndStruct(keyResponse)
+	_, errs := gopay.NewHttpClient().Type(gopay.TypeXML).Post(wxSandboxGetsignkey).SendString(generateXml(reqs)).EndStruct(keyResponse)
 	if len(errs) > 0 {
-		return null, errs[0]
+		return gopay.NULL, errs[0]
 	}
 	if keyResponse.ReturnCode == "FAIL" {
-		return null, errors.New(keyResponse.ReturnMsg)
+		return gopay.NULL, errors.New(keyResponse.ReturnMsg)
 	}
 	return keyResponse.SandboxSignkey, nil
 }
 
 // 生成请求XML的Body体
-func generateXml(bm BodyMap) (reqXml string) {
+func generateXml(bm gopay.BodyMap) (reqXml string) {
 	bs, err := xml.Marshal(bm)
 	if err != nil {
-		return null
+		return gopay.NULL
 	}
 	return string(bs)
 }

+ 45 - 43
wechat_service_api.go → wechat/wechat_service_api.go

@@ -1,4 +1,4 @@
-package gopay
+package wechat
 
 import (
 	"crypto/aes"
@@ -18,6 +18,8 @@ import (
 	"net/http"
 	"reflect"
 	"strings"
+
+	"github.com/iGoogle-ink/gopay"
 )
 
 // 获取微信支付所需参数里的Sign值(通过支付参数计算Sign值)
@@ -26,7 +28,7 @@ import (
 //    mchId:商户ID
 //    ApiKey:API秘钥值
 //    返回参数 sign:通过Appid、MchId、ApiKey和BodyMap中的参数计算出的Sign值
-func GetWeChatParamSign(appId, mchId, apiKey string, bm BodyMap) (sign string) {
+func GetParamSign(appId, mchId, apiKey string, bm gopay.BodyMap) (sign string) {
 	bm.Set("appid", appId)
 	bm.Set("mch_id", mchId)
 	var (
@@ -34,7 +36,7 @@ func GetWeChatParamSign(appId, mchId, apiKey string, bm BodyMap) (sign string) {
 		h        hash.Hash
 	)
 	signType = bm.Get("sign_type")
-	if signType == null {
+	if signType == gopay.NULL {
 		bm.Set("sign_type", SignType_MD5)
 	}
 	if signType == SignType_HMAC_SHA256 {
@@ -53,7 +55,7 @@ func GetWeChatParamSign(appId, mchId, apiKey string, bm BodyMap) (sign string) {
 //    mchId:商户ID
 //    ApiKey:API秘钥值
 //    返回参数 sign:通过Appid、MchId、ApiKey和BodyMap中的参数计算出的Sign值
-func GetWeChatSanBoxParamSign(appId, mchId, apiKey string, bm BodyMap) (sign string, err error) {
+func GetSanBoxParamSign(appId, mchId, apiKey string, bm gopay.BodyMap) (sign string, err error) {
 	bm.Set("appid", appId)
 	bm.Set("mch_id", mchId)
 	bm.Set("sign_type", SignType_MD5)
@@ -61,7 +63,7 @@ func GetWeChatSanBoxParamSign(appId, mchId, apiKey string, bm BodyMap) (sign str
 		sandBoxApiKey string
 		hashMd5       hash.Hash
 	)
-	if sandBoxApiKey, err = getSanBoxKey(mchId, GetRandomString(32), apiKey, SignType_MD5); err != nil {
+	if sandBoxApiKey, err = getSanBoxKey(mchId, gopay.GetRandomString(32), apiKey, SignType_MD5); err != nil {
 		return
 	}
 	hashMd5 = md5.New()
@@ -74,12 +76,12 @@ func GetWeChatSanBoxParamSign(appId, mchId, apiKey string, bm BodyMap) (sign str
 //    req:*http.Request
 //    返回参数bm:Notify请求的参数
 //    返回参数err:错误信息
-func ParseWeChatNotifyResultToBodyMap(req *http.Request) (bm BodyMap, err error) {
+func ParseNotifyResultToBodyMap(req *http.Request) (bm gopay.BodyMap, err error) {
 	bs, err := ioutil.ReadAll(io.LimitReader(req.Body, int64(2<<20))) // default 2MB change the size you want;
 	if err != nil {
 		return nil, fmt.Errorf("ioutil.ReadAll:%s", err.Error())
 	}
-	bm = make(BodyMap)
+	bm = make(gopay.BodyMap)
 	if err = xml.Unmarshal(bs, &bm); err != nil {
 		return nil, fmt.Errorf("xml.Unmarshal:%s", err.Error())
 	}
@@ -90,8 +92,8 @@ func ParseWeChatNotifyResultToBodyMap(req *http.Request) (bm BodyMap, err error)
 //    req:*http.Request
 //    返回参数notifyReq:Notify请求的参数
 //    返回参数err:错误信息
-func ParseWeChatNotifyResult(req *http.Request) (notifyReq *WeChatNotifyRequest, err error) {
-	notifyReq = new(WeChatNotifyRequest)
+func ParseNotifyResult(req *http.Request) (notifyReq *NotifyRequest, err error) {
+	notifyReq = new(NotifyRequest)
 	if err = xml.NewDecoder(req.Body).Decode(notifyReq); err != nil {
 		return nil, fmt.Errorf("xml.NewDecoder:%s", err.Error())
 	}
@@ -102,8 +104,8 @@ func ParseWeChatNotifyResult(req *http.Request) (notifyReq *WeChatNotifyRequest,
 //    req:*http.Request
 //    返回参数notifyReq:Notify请求的参数
 //    返回参数err:错误信息
-func ParseWeChatRefundNotifyResult(req *http.Request) (notifyReq *WeChatRefundNotifyRequest, err error) {
-	notifyReq = new(WeChatRefundNotifyRequest)
+func ParseRefundNotifyResult(req *http.Request) (notifyReq *RefundNotifyRequest, err error) {
+	notifyReq = new(RefundNotifyRequest)
 	if err = xml.NewDecoder(req.Body).Decode(notifyReq); err != nil {
 		return nil, fmt.Errorf("xml.NewDecoder:%s", err.Error())
 	}
@@ -111,7 +113,7 @@ func ParseWeChatRefundNotifyResult(req *http.Request) (notifyReq *WeChatRefundNo
 }
 
 // 解密微信退款异步通知的加密数据
-//    reqInfo:gopay.ParseWeChatRefundNotifyResult() 方法获取的加密数据 req_info
+//    reqInfo:gopay.ParseRefundNotifyResult() 方法获取的加密数据 req_info
 //    apiKey:API秘钥值
 //    返回参数refundNotify:RefundNotify请求的加密数据
 //    返回参数err:错误信息
@@ -148,7 +150,7 @@ func DecryptRefundNotifyReqInfo(reqInfo, apiKey string) (refundNotify *RefundNot
 			dst = dst[blockSize:]
 		}
 	}(encryptionB, encryptionB)
-	bs = PKCS7UnPadding(encryptionB)
+	bs = gopay.PKCS7UnPadding(encryptionB)
 	refundNotify = new(RefundNotify)
 	if err = xml.Unmarshal(bs, refundNotify); err != nil {
 		return nil, fmt.Errorf("xml.Unmarshal:%s", err.Error())
@@ -162,41 +164,41 @@ func DecryptRefundNotifyReqInfo(reqInfo, apiKey string) (refundNotify *RefundNot
 //    bean:微信同步返回的结构体 wxRsp 或 异步通知解析的结构体 notifyReq
 //    返回参数ok:是否验签通过
 //    返回参数err:错误信息
-func VerifyWeChatSign(apiKey, signType string, bean interface{}) (ok bool, err error) {
+func VerifySign(apiKey, signType string, bean interface{}) (ok bool, err error) {
 	if bean == nil {
 		return false, errors.New("bean is nil")
 	}
 	var (
-		bm       BodyMap
+		bm       gopay.BodyMap
 		bs       []byte
 		kind     reflect.Kind
 		bodySign string
 	)
 	kind = reflect.ValueOf(bean).Kind()
 	if kind == reflect.Map {
-		bm = bean.(BodyMap)
+		bm = bean.(gopay.BodyMap)
 		goto Verify
 	}
 	if bs, err = json.Marshal(bean); err != nil {
 		return false, fmt.Errorf("json.Marshal:%s", err.Error())
 	}
-	bm = make(BodyMap)
+	bm = make(gopay.BodyMap)
 	if err = json.Unmarshal(bs, &bm); err != nil {
 		return false, fmt.Errorf("json.Unmarshal:%s", err.Error())
 	}
 Verify:
 	bodySign = bm.Get("sign")
 	bm.Remove("sign")
-	return getWeChatReleaseSign(apiKey, signType, bm) == bodySign, nil
+	return getReleaseSign(apiKey, signType, bm) == bodySign, nil
 }
 
-type WeChatNotifyResponse struct {
+type NotifyResponse struct {
 	ReturnCode string `xml:"return_code"`
 	ReturnMsg  string `xml:"return_msg"`
 }
 
 // 返回数据给微信
-func (w *WeChatNotifyResponse) ToXmlString() (xmlStr string) {
+func (w *NotifyResponse) ToXmlString() (xmlStr string) {
 	var buffer strings.Builder
 	buffer.WriteString("<xml><return_code><![CDATA[")
 	buffer.WriteString(w.ReturnCode)
@@ -321,7 +323,7 @@ func GetAppPaySign(appid, partnerid, noncestr, prepayid, signType, timestamp, ap
 //    sessionKey:会话密钥,通过  gopay.Code2Session() 方法获取到
 //    beanPtr:需要解析到的结构体指针,操作完后,声明的结构体会被赋值
 //    文档:https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/signature.html
-func DecryptWeChatOpenDataToStruct(encryptedData, iv, sessionKey string, beanPtr interface{}) (err error) {
+func DecryptOpenDataToStruct(encryptedData, iv, sessionKey string, beanPtr interface{}) (err error) {
 	var (
 		cipherText, aesKey, ivKey, plainText []byte
 		block                                cipher.Block
@@ -347,7 +349,7 @@ func DecryptWeChatOpenDataToStruct(encryptedData, iv, sessionKey string, beanPtr
 	plainText = make([]byte, len(cipherText))
 	blockMode.CryptBlocks(plainText, cipherText)
 	if len(plainText) > 0 {
-		plainText = PKCS7UnPadding(plainText)
+		plainText = gopay.PKCS7UnPadding(plainText)
 	}
 	if err = json.Unmarshal(plainText, beanPtr); err != nil {
 		return fmt.Errorf("json.Unmarshal:%s", err.Error())
@@ -360,7 +362,7 @@ func DecryptWeChatOpenDataToStruct(encryptedData, iv, sessionKey string, beanPtr
 //    iv:加密算法的初始向量,小程序获取到
 //    sessionKey:会话密钥,通过  gopay.Code2Session() 方法获取到
 //    文档:https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/signature.html
-func DecryptWeChatOpenDataToBodyMap(encryptedData, iv, sessionKey string) (bm BodyMap, err error) {
+func DecryptOpenDataToBodyMap(encryptedData, iv, sessionKey string) (bm gopay.BodyMap, err error) {
 	var (
 		cipherText, aesKey, ivKey, plainText []byte
 		block                                cipher.Block
@@ -379,9 +381,9 @@ func DecryptWeChatOpenDataToBodyMap(encryptedData, iv, sessionKey string) (bm Bo
 		plainText = make([]byte, len(cipherText))
 		blockMode.CryptBlocks(plainText, cipherText)
 		if len(plainText) > 0 {
-			plainText = PKCS7UnPadding(plainText)
+			plainText = gopay.PKCS7UnPadding(plainText)
 		}
-		bm = make(BodyMap)
+		bm = make(gopay.BodyMap)
 		if err = json.Unmarshal(plainText, &bm); err != nil {
 			return nil, fmt.Errorf("json.Unmarshal:%s", err.Error())
 		}
@@ -393,11 +395,11 @@ func DecryptWeChatOpenDataToBodyMap(encryptedData, iv, sessionKey string) (bm Bo
 //    appId:应用唯一标识,在微信开放平台提交应用审核通过后获得
 //    appSecret:应用密钥AppSecret,在微信开放平台提交应用审核通过后获得
 //    code:App用户换取access_token的code
-func GetAppWeChatLoginAccessToken(appId, appSecret, code string) (accessToken *AppWeChatLoginAccessToken, err error) {
-	accessToken = new(AppWeChatLoginAccessToken)
+func GetAppLoginAccessToken(appId, appSecret, code string) (accessToken *AppLoginAccessToken, err error) {
+	accessToken = new(AppLoginAccessToken)
 	url := "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + appId + "&secret=" + appSecret + "&code=" + code + "&grant_type=authorization_code"
 
-	_, errs := NewHttpClient().Get(url).EndStruct(accessToken)
+	_, errs := gopay.NewHttpClient().Get(url).EndStruct(accessToken)
 	if len(errs) > 0 {
 		return nil, errs[0]
 	}
@@ -408,11 +410,11 @@ func GetAppWeChatLoginAccessToken(appId, appSecret, code string) (accessToken *A
 //    appId:应用唯一标识,在微信开放平台提交应用审核通过后获得
 //    appSecret:应用密钥AppSecret,在微信开放平台提交应用审核通过后获得
 //    code:App用户换取access_token的code
-func RefreshAppWeChatLoginAccessToken(appId, refreshToken string) (accessToken *RefreshAppWeChatLoginAccessTokenRsp, err error) {
-	accessToken = new(RefreshAppWeChatLoginAccessTokenRsp)
+func RefreshAppLoginAccessToken(appId, refreshToken string) (accessToken *RefreshAppLoginAccessTokenRsp, err error) {
+	accessToken = new(RefreshAppLoginAccessTokenRsp)
 	url := "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=" + appId + "&grant_type=refresh_token&refresh_token=" + refreshToken
 
-	_, errs := NewHttpClient().Get(url).EndStruct(accessToken)
+	_, errs := gopay.NewHttpClient().Get(url).EndStruct(accessToken)
 	if len(errs) > 0 {
 		return nil, errs[0]
 	}
@@ -427,7 +429,7 @@ func RefreshAppWeChatLoginAccessToken(appId, refreshToken string) (accessToken *
 func Code2Session(appId, appSecret, wxCode string) (sessionRsp *Code2SessionRsp, err error) {
 	sessionRsp = new(Code2SessionRsp)
 	url := "https://api.weixin.qq.com/sns/jscode2session?appid=" + appId + "&secret=" + appSecret + "&js_code=" + wxCode + "&grant_type=authorization_code"
-	_, errs := NewHttpClient().Get(url).EndStruct(sessionRsp)
+	_, errs := gopay.NewHttpClient().Get(url).EndStruct(sessionRsp)
 	if len(errs) > 0 {
 		return nil, errs[0]
 	}
@@ -438,10 +440,10 @@ func Code2Session(appId, appSecret, wxCode string) (sessionRsp *Code2SessionRsp,
 //    appId:APPID
 //    appSecret:AppSecret
 //    获取access_token文档:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/access-token/auth.getAccessToken.html
-func GetWeChatAppletAccessToken(appId, appSecret string) (accessToken *AccessToken, err error) {
+func GetAppletAccessToken(appId, appSecret string) (accessToken *AccessToken, err error) {
 	accessToken = new(AccessToken)
 	url := "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appId + "&secret=" + appSecret
-	_, errs := NewHttpClient().Get(url).EndStruct(accessToken)
+	_, errs := gopay.NewHttpClient().Get(url).EndStruct(accessToken)
 	if len(errs) > 0 {
 		return nil, errs[0]
 	}
@@ -458,18 +460,18 @@ func GetWeChatAppletAccessToken(appId, appSecret string) (accessToken *AccessTok
 func GetOpenIdByAuthCode(appId, mchId, apiKey, authCode, nonceStr string) (openIdRsp *OpenIdByAuthCodeRsp, err error) {
 	var (
 		url string
-		bm  BodyMap
+		bm  gopay.BodyMap
 	)
 	url = "https://api.mch.weixin.qq.com/tools/authcodetoopenid"
-	bm = make(BodyMap)
+	bm = make(gopay.BodyMap)
 	bm.Set("appid", appId)
 	bm.Set("mch_id", mchId)
 	bm.Set("auth_code", authCode)
 	bm.Set("nonce_str", nonceStr)
-	bm.Set("sign", getWeChatReleaseSign(apiKey, SignType_MD5, bm))
+	bm.Set("sign", getReleaseSign(apiKey, SignType_MD5, bm))
 
 	openIdRsp = new(OpenIdByAuthCodeRsp)
-	_, errs := NewHttpClient().Type(TypeXML).Post(url).SendString(generateXml(bm)).EndStruct(openIdRsp)
+	_, errs := gopay.NewHttpClient().Type(gopay.TypeXML).Post(url).SendString(generateXml(bm)).EndStruct(openIdRsp)
 	if len(errs) > 0 {
 		return nil, errs[0]
 	}
@@ -481,10 +483,10 @@ func GetOpenIdByAuthCode(appId, mchId, apiKey, authCode, nonceStr string) (openI
 //    openId:用户的OpenID
 //    transactionId:微信支付订单号
 //    文档:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/user-info/auth.getPaidUnionId.html
-func GetWeChatAppletPaidUnionId(accessToken, openId, transactionId string) (unionId *PaidUnionId, err error) {
+func GetAppletPaidUnionId(accessToken, openId, transactionId string) (unionId *PaidUnionId, err error) {
 	unionId = new(PaidUnionId)
 	url := "https://api.weixin.qq.com/wxa/getpaidunionid?access_token=" + accessToken + "&openid=" + openId + "&transaction_id=" + transactionId
-	_, errs := NewHttpClient().Get(url).EndStruct(unionId)
+	_, errs := gopay.NewHttpClient().Get(url).EndStruct(unionId)
 	if len(errs) > 0 {
 		return nil, errs[0]
 	}
@@ -496,13 +498,13 @@ func GetWeChatAppletPaidUnionId(accessToken, openId, transactionId string) (unio
 //    openId:用户的OpenID
 //    lang:默认为 zh_CN ,可选填 zh_CN 简体,zh_TW 繁体,en 英语
 //    获取用户基本信息(UnionID机制)文档:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140839
-func GetWeChatUserInfo(accessToken, openId string, lang ...string) (userInfo *WeChatUserInfo, err error) {
-	userInfo = new(WeChatUserInfo)
+func GetUserInfo(accessToken, openId string, lang ...string) (userInfo *UserInfo, err error) {
+	userInfo = new(UserInfo)
 	url := "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + accessToken + "&openid=" + openId + "&lang=zh_CN"
 	if len(lang) > 0 {
 		url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + accessToken + "&openid=" + openId + "&lang=" + lang[0]
 	}
-	_, errs := NewHttpClient().Get(url).EndStruct(userInfo)
+	_, errs := gopay.NewHttpClient().Get(url).EndStruct(userInfo)
 	if len(errs) > 0 {
 		return nil, errs[0]
 	}