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DVR0OBBYEFJ2Kx9YZfmWpkKFnC33C0r5D
K3rFMAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgeAMA0GCSqGSIb3DQEBCwUA
A4IBAQBZoeU0XyH9O0LGF9R+JyGwfU/O5amoB97VeM+5n9v2z8OCiIJ8eXVGKN9L
tl9QkpTEanYwK30KkpHcJP1xfVkhPi/cCMgfTWQ5eKYC7Zm16zk7n4CP6IIgZIqm
TVGsIGKk8RzWseyWPB3lfqMDR52V1tdA1S8lJ7a2Xnpt5M2jkDXoArl3SVSwCb4D
AmThYhak48M++fUJNYII9JBGRdRGbfJ2GSFdPXgesUL2CwlReQwbW4GZkYGOg9LK
CNPK6XShlNdvgPv0CCR08KCYRwC3HZ0y1F0NjaKzYdGNPrvOq9lA495ONZCvzYDo
gmsu/kd6eqxTs/JwdaIYr4sCMg8Z
-----END CERTIFICATE-----
package pay package pay
import ( import (
"crypto"
"crypto/rsa"
"crypto/sha256"
"crypto/x509"
"encoding/base64"
"encoding/pem"
"errors"
"fmt" "fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"io/ioutil"
"system_pay/controller/base" "system_pay/controller/base"
"system_pay/models" "system_pay/models"
"system_pay/repository/pay" "system_pay/repository/pay"
...@@ -39,13 +47,13 @@ func (l *PayController) WxNotice(c *gin.Context) { ...@@ -39,13 +47,13 @@ func (l *PayController) WxNotice(c *gin.Context) {
//fmt.Println(ph2) //fmt.Println(ph2)
//验证签名 //验证签名
//_, err := verySignByPublicKey(c) _, err := verySignByPublicKey(c)
//if err != nil { if err != nil {
// fmt.Println(err) fmt.Println("verySignByPublicKey err: ", err)
//} }
ph := new(models.WxNoticeInput) ph := new(models.WxNoticeInput)
err := c.ShouldBindJSON(ph) err = c.ShouldBindJSON(ph)
if err != nil { if err != nil {
response := new(base.ResponseDataWxNotice) response := new(base.ResponseDataWxNotice)
response.Code = "FAIL" response.Code = "FAIL"
...@@ -95,50 +103,54 @@ func (l *PayController) WxNotice(c *gin.Context) { ...@@ -95,50 +103,54 @@ func (l *PayController) WxNotice(c *gin.Context) {
// return errors.New("wangpei签名测试中。。。。。") // return errors.New("wangpei签名测试中。。。。。")
//} //}
//func verySignByPublicKey(c *gin.Context) (bool, error) { func verySignByPublicKey(c *gin.Context) (bool, error) {
//
// //publicKey string, data []byte, signData []byte //publicKey string, data []byte, signData []byte
// //String responseStr = IOUtils.toString(response.getEntity().getContent(), ENCODING); //String responseStr = IOUtils.toString(response.getEntity().getContent(), ENCODING);
// appid := c.GetHeader("Lklapi-Appid") appid := c.GetHeader("Lklapi-Appid")
// lklapiSerial := c.GetHeader("Lklapi-Serial") lklapiSerial := c.GetHeader("Lklapi-Serial")
// timestamp := c.GetHeader("Lklapi-Timestamp") timestamp := c.GetHeader("Lklapi-Timestamp")
// nonce := c.GetHeader("Lklapi-Nonce") nonce := c.GetHeader("Lklapi-Nonce")
// signature := c.GetHeader("Lklapi-Signature") signature := c.GetHeader("Lklapi-Signature")
// responseStr := c.GetHeader("") responseStr := c.GetHeader("")
//
// source := appid + "\n" + lklapiSerial + "\n" + timestamp + "\n" + nonce + "\n" + responseStr + "\n"; data := appid + "\n" + lklapiSerial + "\n" + timestamp + "\n" + nonce + "\n" + responseStr + "\n";
// fmt.Println("verySignByPublicKey start...")
// publicKey = fmt.Println(data)
// signData fmt.Println("signature="+signature)
// publicKey = FormatPrivateKey(publicKey)
// // 2、解码私钥字节,生成加密对象 // 1、读取公钥文件,获取公钥字节
// block, _ := pem.Decode([]byte(publicKey)) publicKey, err := ioutil.ReadFile("../cert/lkl-apigw-v2.cer")
// if block == nil { if err != nil {
// return false, errors.New("私钥信息错误!") return false, err
// } }
// // 3、解析DER编码的私钥,生成私钥对象 // 2、解码私钥字节,生成加密对象
// pubKey, err := x509.ParsePKIXPublicKey(block.Bytes) block, _ := pem.Decode(publicKey)
// if err != nil { if block == nil {
// return false, err return false, errors.New("私钥信息错误!")
// } }
// // 3、解析DER编码的私钥,生成私钥对象
// hashed := sha256.Sum256(data) pubKey, err := x509.ParsePKIXPublicKey(block.Bytes)
// if err != nil {
// fmt.Println("pubKey.(*rsa.PublicKey): ", pubKey.(*rsa.PublicKey)) return false, err
// }
// pubK := pubKey.(*rsa.PublicKey)
// hashed := sha256.Sum256([]byte(data))
// sig, err := base64.StdEncoding.DecodeString(string(signData))
// fmt.Println("err: ", err) fmt.Println("pubKey.(*rsa.PublicKey): ", pubKey.(*rsa.PublicKey))
//
// err = rsa.VerifyPKCS1v15(pubK, crypto.SHA256, hashed[:], sig) pubK := pubKey.(*rsa.PublicKey)
// if err != nil {
// return false, err sig, err := base64.StdEncoding.DecodeString(signature)
// }
// err = rsa.VerifyPKCS1v15(pubK, crypto.SHA256, hashed[:], sig)
// return true, nil if err != nil {
//} return false, err
// }
return true, nil
}
//const ( //const (
// PEM_BEGIN = "-----BEGIN RSA PRIVATE KEY-----\n" // PEM_BEGIN = "-----BEGIN RSA PRIVATE KEY-----\n"
// PEM_END = "\n-----END RSA PRIVATE KEY-----" // PEM_END = "\n-----END RSA PRIVATE KEY-----"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment