mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-04 12:52:27 +08:00
feat: create mini program virtual payment (#709)
This commit is contained in:
@@ -6,7 +6,7 @@ import (
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// CommonError 微信返回的通用错误json
|
||||
// CommonError 微信返回的通用错误 json
|
||||
type CommonError struct {
|
||||
apiName string
|
||||
ErrCode int64 `json:"errcode"`
|
||||
@@ -17,7 +17,7 @@ func (c *CommonError) Error() string {
|
||||
return fmt.Sprintf("%s Error , errcode=%d , errmsg=%s", c.apiName, c.ErrCode, c.ErrMsg)
|
||||
}
|
||||
|
||||
// NewCommonError 新建CommonError错误,对于无errcode和errmsg的返回也可以返回该通用错误
|
||||
// NewCommonError 新建 CommonError 错误,对于无 errcode 和 errmsg 的返回也可以返回该通用错误
|
||||
func NewCommonError(apiName string, code int64, msg string) *CommonError {
|
||||
return &CommonError{
|
||||
apiName: apiName,
|
||||
@@ -26,7 +26,7 @@ func NewCommonError(apiName string, code int64, msg string) *CommonError {
|
||||
}
|
||||
}
|
||||
|
||||
// DecodeWithCommonError 将返回值按照CommonError解析
|
||||
// DecodeWithCommonError 将返回值按照 CommonError 解析
|
||||
func DecodeWithCommonError(response []byte, apiName string) (err error) {
|
||||
var commError CommonError
|
||||
err = json.Unmarshal(response, &commError)
|
||||
|
||||
@@ -100,7 +100,7 @@ func PostJSON(uri string, obj interface{}) ([]byte, error) {
|
||||
return PostJSONContext(context.Background(), uri, obj)
|
||||
}
|
||||
|
||||
// PostJSONWithRespContentType post json数据请求,且返回数据类型
|
||||
// PostJSONWithRespContentType post json 数据请求,且返回数据类型
|
||||
func PostJSONWithRespContentType(uri string, obj interface{}) ([]byte, string, error) {
|
||||
jsonBuf := new(bytes.Buffer)
|
||||
enc := json.NewEncoder(jsonBuf)
|
||||
@@ -216,7 +216,7 @@ func PostXML(uri string, obj interface{}) ([]byte, error) {
|
||||
return io.ReadAll(response.Body)
|
||||
}
|
||||
|
||||
// httpWithTLS CA证书
|
||||
// httpWithTLS CA 证书
|
||||
func httpWithTLS(rootCa, key string) (*http.Client, error) {
|
||||
var client *http.Client
|
||||
certData, err := os.ReadFile(rootCa)
|
||||
@@ -235,7 +235,7 @@ func httpWithTLS(rootCa, key string) (*http.Client, error) {
|
||||
return client, nil
|
||||
}
|
||||
|
||||
// pkcs12ToPem 将Pkcs12转成Pem
|
||||
// pkcs12ToPem 将 Pkcs12 转成 Pem
|
||||
func pkcs12ToPem(p12 []byte, password string) tls.Certificate {
|
||||
blocks, err := pkcs12.ToPEM(p12, password)
|
||||
defer func() {
|
||||
|
||||
Reference in New Issue
Block a user