fix:
This commit is contained in:
parent
7ebc4ec589
commit
09685704f5
|
@ -319,20 +319,20 @@ func OpenMember(c *gin.Context) {
|
||||||
RespJson(c, status.InternalServerError, nil)
|
RespJson(c, status.InternalServerError, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
webPay, err := wxpay.WebPay(orderSn, totalFee, user.WxOpenID, "N", wxpay.WxPayMember, configInfo.NotifyUrl)
|
//webPay, err := wxpay.WebPay(orderSn, totalFee, user.WxOpenID, "N", wxpay.WxPayMember, configInfo.NotifyUrl)
|
||||||
if err != nil {
|
|
||||||
logger.Error(errors.New("WebPay err"))
|
|
||||||
RespJson(c, status.InternalServerError, nil)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
//webPay, err := wxpay.HmJsPayUnifiedOrder(orderSn, totalFee, user.WxOpenID, "N", wxpay.WxPayRentCard, configInfo.NotifyUrl)
|
|
||||||
//if err != nil {
|
//if err != nil {
|
||||||
// logger.Error(errors.New("WebPay err"))
|
// logger.Error(errors.New("WebPay err"))
|
||||||
// RespJson(c, status.InternalServerError, nil)
|
// RespJson(c, status.InternalServerError, nil)
|
||||||
// return
|
// return
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
webPay, err := wxpay.HmJsPayUnifiedOrder(orderSn, totalFee, user.WxOpenID, "N", wxpay.WxPayRentCard, configInfo.NotifyUrl)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error(errors.New("WebPay err"))
|
||||||
|
RespJson(c, status.InternalServerError, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
RespOK(c, webPay)
|
RespOK(c, webPay)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -976,20 +976,22 @@ type HmJsPayUnifiedOrderReq struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type HmPayBizContent struct {
|
type HmPayBizContent struct {
|
||||||
Body string `json:"body"`
|
Body string `json:"body"`
|
||||||
BuyerId string `json:"buyer_id"`
|
MerAppId string `json:"mer_app_id"`
|
||||||
CreateIp string `json:"create_ip"`
|
//BuyerId string `json:"buyer_id"`
|
||||||
CreateTime string `json:"create_time"`
|
MerBuyerId string `json:"mer_buyer_id"`
|
||||||
DiscountInfo struct {
|
CreateIp string `json:"create_ip"`
|
||||||
DiscountableAmount float64 `json:"discountable_amount"`
|
CreateTime string `json:"create_time"`
|
||||||
} `json:"discount_info"`
|
//DiscountInfo struct {
|
||||||
ExpireTime string `json:"expire_time"`
|
// DiscountableAmount float64 `json:"discountable_amount"`
|
||||||
ExtendParams struct {
|
//} `json:"discount_info"`
|
||||||
AccessPartyCode string `json:"access_party_code"`
|
ExpireTime string `json:"expire_time"`
|
||||||
} `json:"extend_params"`
|
//ExtendParams struct {
|
||||||
GoodsDetails []HmPayGoodsDetails `json:"goods_details"`
|
// AccessPartyCode string `json:"access_party_code"`
|
||||||
LimitPay string `json:"limit_pay"`
|
//} `json:"extend_params"`
|
||||||
NotifyUrl string `json:"notify_url"`
|
//GoodsDetails []HmPayGoodsDetails `json:"goods_details"`
|
||||||
|
LimitPay string `json:"limit_pay"`
|
||||||
|
NotifyUrl string `json:"notify_url"`
|
||||||
//OperatorId string `json:"operator_id"`
|
//OperatorId string `json:"operator_id"`
|
||||||
OutOrderNo string `json:"out_order_no"`
|
OutOrderNo string `json:"out_order_no"`
|
||||||
PayType string `json:"pay_type"`
|
PayType string `json:"pay_type"`
|
||||||
|
@ -1071,27 +1073,12 @@ func HmJsPayUnifiedOrder(orderId string, totalFee uint32, openId, profitSharing,
|
||||||
}
|
}
|
||||||
|
|
||||||
biz := HmPayBizContent{
|
biz := HmPayBizContent{
|
||||||
Body: "会员费",
|
Body: "会员费",
|
||||||
BuyerId: openId,
|
MerAppId: WxAppId,
|
||||||
CreateIp: clientIp,
|
MerBuyerId: openId,
|
||||||
CreateTime: strTime,
|
CreateIp: clientIp,
|
||||||
DiscountInfo: struct {
|
CreateTime: strTime,
|
||||||
DiscountableAmount float64 `json:"discountable_amount"`
|
ExpireTime: strExpireTime,
|
||||||
}{},
|
|
||||||
ExpireTime: strExpireTime,
|
|
||||||
ExtendParams: struct {
|
|
||||||
AccessPartyCode string `json:"access_party_code"`
|
|
||||||
}{},
|
|
||||||
GoodsDetails: []HmPayGoodsDetails{
|
|
||||||
{
|
|
||||||
Body: "会员",
|
|
||||||
GoodsId: "1",
|
|
||||||
GoodsName: "会员服务",
|
|
||||||
Price: 399,
|
|
||||||
Quantity: 1,
|
|
||||||
ShowUrl: "",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
LimitPay: "NO_CREDIT",
|
LimitPay: "NO_CREDIT",
|
||||||
NotifyUrl: notifyUrl,
|
NotifyUrl: notifyUrl,
|
||||||
OutOrderNo: orderId,
|
OutOrderNo: orderId,
|
||||||
|
@ -1132,6 +1119,17 @@ func HmJsPayUnifiedOrder(orderId string, totalFee uint32, openId, profitSharing,
|
||||||
logger.Errorf("WxUnifiedOrder unified order error %#v", err)
|
logger.Errorf("WxUnifiedOrder unified order error %#v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
signContent, err := ToSignContent(unifiedOrderResp)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("ToSignContent err:", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
err = HmVerifySha1Rsa(signContent, unifiedOrderResp.Sign)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("HmVerifySha1Rsa err:", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
//fmt.Println("unifiedOrderResp:", unifiedOrderResp.Data)
|
//fmt.Println("unifiedOrderResp:", unifiedOrderResp.Data)
|
||||||
var hmPayDetail HmPayUnifiedOrderDetail
|
var hmPayDetail HmPayUnifiedOrderDetail
|
||||||
err = json.Unmarshal([]byte(unifiedOrderResp.Data), &hmPayDetail)
|
err = json.Unmarshal([]byte(unifiedOrderResp.Data), &hmPayDetail)
|
||||||
|
@ -1152,6 +1150,34 @@ func HmJsPayUnifiedOrder(orderId string, totalFee uint32, openId, profitSharing,
|
||||||
return &hmPayData, nil
|
return &hmPayData, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ToSignContent(s interface{}) (string, error) {
|
||||||
|
m, err := struct2Map(s)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error(err)
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
delete(m, "sign")
|
||||||
|
var signData []string
|
||||||
|
for k, v := range m {
|
||||||
|
if k == "openid" {
|
||||||
|
fmt.Println(k, ":", v)
|
||||||
|
}
|
||||||
|
if v != "" && v != "0" {
|
||||||
|
signData = append(signData, fmt.Sprintf("%s=%s", k, v))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Strings(signData)
|
||||||
|
|
||||||
|
//signDataJson2, _ := json.MarshalIndent(&signData, "", " ")
|
||||||
|
//fmt.Println("signDataJson2", string(signDataJson2))
|
||||||
|
|
||||||
|
signStr := strings.Join(signData, "&")
|
||||||
|
|
||||||
|
return signStr, nil
|
||||||
|
}
|
||||||
|
|
||||||
func GenHmPaySign(m map[string]string) (string, error) {
|
func GenHmPaySign(m map[string]string) (string, error) {
|
||||||
delete(m, "sign")
|
delete(m, "sign")
|
||||||
var signData []string
|
var signData []string
|
||||||
|
@ -1203,8 +1229,8 @@ func Sha1withRsa(signContent string) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParsePrivateKey() (*rsa.PrivateKey, error) {
|
func ParsePrivateKey() (*rsa.PrivateKey, error) {
|
||||||
fp := "/Users/li/mh/mh_server/pack/configs/hm_pay/private_key.pem"
|
//fp := "/Users/li/mh/mh_server/pack/configs/hm_pay/private_key.pem"
|
||||||
//fp := "./configs/hm_pay/private_key.pem"
|
fp := "./configs/hm_pay/private_key.pem"
|
||||||
privateKey, err := ioutil.ReadFile(fp)
|
privateKey, err := ioutil.ReadFile(fp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("read file err:", err)
|
logger.Error("read file err:", err)
|
||||||
|
@ -1227,21 +1253,67 @@ func ParsePrivateKey() (*rsa.PrivateKey, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
PEM_BEGIN = "-----BEGIN RSA PRIVATE KEY-----\n"
|
PemBegin = "-----BEGIN RSA PRIVATE KEY-----\n"
|
||||||
PEM_END = "\n-----END RSA PRIVATE KEY-----"
|
PemEnd = "\n-----END RSA PRIVATE KEY-----"
|
||||||
)
|
)
|
||||||
|
|
||||||
func FormatPrivateKey(privateKey string) string {
|
func FormatPrivateKey(privateKey string) string {
|
||||||
//privateKey = strings.Trim(privateKey, "\n")
|
//privateKey = strings.Trim(privateKey, "\n")
|
||||||
if !strings.HasPrefix(privateKey, PEM_BEGIN) {
|
if !strings.HasPrefix(privateKey, PemBegin) {
|
||||||
privateKey = PEM_BEGIN + privateKey
|
privateKey = PemBegin + privateKey
|
||||||
}
|
}
|
||||||
if !strings.HasSuffix(privateKey, PEM_END) {
|
if !strings.HasSuffix(privateKey, PemEnd) {
|
||||||
privateKey = privateKey + PEM_END
|
privateKey = privateKey + PemEnd
|
||||||
}
|
}
|
||||||
return privateKey
|
return privateKey
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const HmPubKey = `MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDzGVH0Fxpb2M48U1BWr6lpNs2W3VHqtjO8X5RqWjtTwpQVKo8dqaiAGxVbsdnefPpsbI5l9rKquRAOJhWFU07hxSUgXZOk55QQmll03MBgRDXLgxyKfycLLQwhsCJAzDIWC7IWgok/RHV9m9AV2GbQxWBl+7iDE4prcbpgG8Z0HwIDAQAB`
|
||||||
|
|
||||||
|
func HmVerifySha1Rsa(signContent, signBase string) error {
|
||||||
|
//fp := "/Users/li/mh/mh_server/pack/configs/hm_pay/public_key.pme"
|
||||||
|
//publicKeyString, err := ioutil.ReadFile(fp)
|
||||||
|
//if err != nil {
|
||||||
|
// fmt.Println("read file err:", err)
|
||||||
|
// return err
|
||||||
|
//}
|
||||||
|
|
||||||
|
block, _ := pem.Decode([]byte(FormatPrivateKey(HmPubKey)))
|
||||||
|
if block == nil {
|
||||||
|
fmt.Println("decode block is nil")
|
||||||
|
return errors.New("decode block is nil")
|
||||||
|
}
|
||||||
|
publicKey, err := x509.ParsePKIXPublicKey(block.Bytes)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("public key err:", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if publicKey == nil {
|
||||||
|
fmt.Println("public key nil:")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
hash := crypto.SHA1
|
||||||
|
shaNew := hash.New()
|
||||||
|
shaNew.Write([]byte(signContent))
|
||||||
|
hashed := shaNew.Sum(nil)
|
||||||
|
|
||||||
|
sign, err := b64.StdEncoding.DecodeString(signBase)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("sign decode err:", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = rsa.VerifyPKCS1v15(publicKey.(*rsa.PublicKey), hash, hashed, sign)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("verify err:", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
//logger.Error("验签成功")
|
||||||
|
fmt.Println("验签成功")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func VerifySha1Rsa(signContent, signBase string) error {
|
func VerifySha1Rsa(signContent, signBase string) error {
|
||||||
fp := "/Users/li/mh/mh_server/pack/configs/hm_pay/public_key.pme"
|
fp := "/Users/li/mh/mh_server/pack/configs/hm_pay/public_key.pme"
|
||||||
publicKeyString, err := ioutil.ReadFile(fp)
|
publicKeyString, err := ioutil.ReadFile(fp)
|
||||||
|
@ -1251,6 +1323,10 @@ func VerifySha1Rsa(signContent, signBase string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
block, _ := pem.Decode([]byte(publicKeyString))
|
block, _ := pem.Decode([]byte(publicKeyString))
|
||||||
|
if block == nil {
|
||||||
|
fmt.Println("decode block is nil")
|
||||||
|
return errors.New("decode block is nil")
|
||||||
|
}
|
||||||
publicKey, err := x509.ParsePKIXPublicKey(block.Bytes)
|
publicKey, err := x509.ParsePKIXPublicKey(block.Bytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("public key err:", err)
|
fmt.Println("public key err:", err)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user