Compare commits
3 Commits
99aa763357
...
96aa3b16da
Author | SHA1 | Date |
---|---|---|
|
96aa3b16da | |
|
fd57130499 | |
|
67265ef3fc |
|
@ -53,6 +53,9 @@ const (
|
||||||
AppDeEncryptFail = 1250
|
AppDeEncryptFail = 1250
|
||||||
// 加密方式不存在
|
// 加密方式不存在
|
||||||
EncryptTypeNotFound = 1241
|
EncryptTypeNotFound = 1241
|
||||||
|
PayChannelConfigNotFound = 1242
|
||||||
|
// 加密参数异常
|
||||||
|
PayEncryptParamFail = 1243
|
||||||
|
|
||||||
//渠道
|
//渠道
|
||||||
PayChannelNotFound = 1300
|
PayChannelNotFound = 1300
|
||||||
|
@ -139,6 +142,8 @@ var MsgZH = map[int]string{
|
||||||
AppAesEncryptFail: "aes 加密失败",
|
AppAesEncryptFail: "aes 加密失败",
|
||||||
|
|
||||||
EncryptTypeNotFound: "加密方式不存在",
|
EncryptTypeNotFound: "加密方式不存在",
|
||||||
|
PayChannelConfigNotFound: "secret支付方式配置不存在",
|
||||||
|
PayEncryptParamFail: "加密参数错误,解析失败",
|
||||||
|
|
||||||
AppDeEncryptFail: "未知原因导致解密失败,请检查加密数据是和app加密配置",
|
AppDeEncryptFail: "未知原因导致解密失败,请检查加密数据是和app加密配置",
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,8 @@ package front
|
||||||
import (
|
import (
|
||||||
"PaymentCenter/app/constants/common"
|
"PaymentCenter/app/constants/common"
|
||||||
"PaymentCenter/app/constants/errorcode"
|
"PaymentCenter/app/constants/errorcode"
|
||||||
|
"PaymentCenter/app/http/controllers"
|
||||||
|
"PaymentCenter/app/http/entities/front"
|
||||||
"PaymentCenter/app/models/paychannelmodel"
|
"PaymentCenter/app/models/paychannelmodel"
|
||||||
"PaymentCenter/app/services"
|
"PaymentCenter/app/services"
|
||||||
"PaymentCenter/app/third/paymentService"
|
"PaymentCenter/app/third/paymentService"
|
||||||
|
@ -190,22 +192,22 @@ func BrokerWechatUrl(c *gin.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//// 首页
|
// 首页
|
||||||
//func Ind/*ex(c *gin.Context) {
|
func Index(c *gin.Context) {
|
||||||
// c.HTML(200, "index.html", gin.H{})
|
c.HTML(200, "index.html", gin.H{})
|
||||||
//}
|
}
|
||||||
|
|
||||||
//// 获取微信授权链接
|
// 获取微信授权链接
|
||||||
//func GetWxAuthUrl(c *gin.Context) {
|
func GetWxAuthUrl(c *gin.Context) {
|
||||||
// req, _ := controllers.GetRequest(c).(*front.GetWxAuthUrlRequest)
|
req, _ := controllers.GetRequest(c).(*front.GetWxAuthUrlRequest)
|
||||||
//
|
|
||||||
// url, code := services.GetWxAuthUrl(*req)
|
url, code := services.GetWxAuthUrl(*req)
|
||||||
// controllers.HandCodeRes(c, url, code)
|
controllers.HandCodeRes(c, url, code)
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//// 通过code获取授权,openid
|
// 通过code获取授权,openid
|
||||||
//func GetWxAuth(c *gin.Context) {
|
func GetWxAuth(c *gin.Context) {
|
||||||
// //req, _ := controllers.GetRequest(c).(*front.GetWxAuthRequest)
|
req, _ := controllers.GetRequest(c).(*front.GetWxAuthRequest)
|
||||||
// //openId, code := services.GetWxAuth(*req)
|
code := services.GetWxAuth(*req)
|
||||||
// //controllers.HandCodeRes(c, openId, code)
|
controllers.HandCodeRes(c, code, code)
|
||||||
//}*/
|
}
|
||||||
|
|
|
@ -69,12 +69,12 @@ func RegisterRoute(router *gin.Engine) {
|
||||||
|
|
||||||
// 微信获取授权相关
|
// 微信获取授权相关
|
||||||
router.LoadHTMLGlob("./front/templates/*")
|
router.LoadHTMLGlob("./front/templates/*")
|
||||||
//wx := v1.Group("/wx", middlewares.ValidateRequest())
|
wx := v1.Group("/wx", middlewares.ValidateRequest())
|
||||||
//{
|
{
|
||||||
// wx.GET("/index", front.Index) // 获取页面
|
wx.GET("/index", front.Index) // 获取页面
|
||||||
// wx.POST("/getWxAuthUrl", front.GetWxAuthUrl) // 获取授权code
|
wx.POST("/getWxAuthUrl", front.GetWxAuthUrl) // 获取授权code
|
||||||
// wx.GET("/getWxAuth", front.GetWxAuth) // 获取openId
|
wx.GET("/getWxAuth", front.GetWxAuth) // 获取openId
|
||||||
//}
|
}
|
||||||
|
|
||||||
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ func (a *AppCheck) Crypt() (cryptFunc func(app *appmodel.App) apicrypt.ApiCrypt)
|
||||||
func (a *AppCheck) ReCheckAfterDecrypt(data []byte, requestData *front.RequestBody) bool {
|
func (a *AppCheck) ReCheckAfterDecrypt(data []byte, requestData *front.RequestBody) bool {
|
||||||
var requestCommonData front.ApiCommonBody
|
var requestCommonData front.ApiCommonBody
|
||||||
if err := sonic.Unmarshal(data, &requestCommonData); err != nil {
|
if err := sonic.Unmarshal(data, &requestCommonData); err != nil {
|
||||||
a.Code = errorcode.ParamError
|
a.Code = errorcode.PayEncryptParamFail
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if requestCommonData.AppId != requestData.AppId || requestCommonData.Timestamp != requestData.Timestamp {
|
if requestCommonData.AppId != requestData.AppId || requestCommonData.Timestamp != requestData.Timestamp {
|
||||||
|
|
|
@ -2,11 +2,14 @@ package services
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"PaymentCenter/app/constants/common"
|
"PaymentCenter/app/constants/common"
|
||||||
|
"PaymentCenter/app/constants/errorcode"
|
||||||
"PaymentCenter/app/http/entities/front"
|
"PaymentCenter/app/http/entities/front"
|
||||||
"PaymentCenter/app/models/paychannelmodel"
|
"PaymentCenter/app/models/paychannelmodel"
|
||||||
"PaymentCenter/app/third/paymentService"
|
"PaymentCenter/app/utils"
|
||||||
|
"PaymentCenter/app/utils/httpclient"
|
||||||
"PaymentCenter/config"
|
"PaymentCenter/config"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
@ -47,7 +50,7 @@ func GetWxAuthUrl(param front.GetWxAuthUrlRequest) (targetUrl string, code int)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 通过code换取网页授权access_token
|
// // 通过code换取网页授权access_token
|
||||||
func GetWxAuth(param front.GetWxAuthRequest) (code int) {
|
func GetWxAuth(param front.GetWxAuthRequest) (code int) {
|
||||||
|
|
||||||
// 获取支付渠道的配置
|
// 获取支付渠道的配置
|
||||||
|
@ -62,19 +65,35 @@ func GetWxAuth(param front.GetWxAuthRequest) (code int) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 配置解析
|
//// 配置解析
|
||||||
wxConfig := paymentService.WxPay{}
|
wxConfig := make(map[string]interface{})
|
||||||
err = json.Unmarshal([]byte(payChannel.ExtJson), &wxConfig)
|
err = json.Unmarshal([]byte(payChannel.ExtJson), &wxConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
code = handErr(err)
|
code = handErr(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
sk := wxConfig["secret"].(string)
|
||||||
|
if sk == "" {
|
||||||
|
code = errorcode.PayChannelConfigNotFound
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
//targetUrl := fmt.Sprintf("https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code",
|
targetUrl := fmt.Sprintf("https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code",
|
||||||
// payChannel.AppId,
|
payChannel.AppId,
|
||||||
// wxConfig.SerialNo,
|
sk,
|
||||||
// param.Code,
|
param.Code,
|
||||||
//)
|
)
|
||||||
|
|
||||||
|
header := map[string]string{
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
}
|
||||||
|
body := map[string]string{}
|
||||||
|
response, err := httpclient.FastHttpGet(targetUrl, header, body, 0)
|
||||||
|
if err != nil {
|
||||||
|
code = handErr(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
utils.Log(nil, "获取微信授权信息", string(response), targetUrl)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,13 @@ func PrivateKeyToString(privateKey *sm2.PrivateKey) string {
|
||||||
return strings.ToUpper(hex.EncodeToString(privateKey.D.Bytes()))
|
return strings.ToUpper(hex.EncodeToString(privateKey.D.Bytes()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func SM2Decrypt(cipherText, publicKey string, privateKey string) (string, error) {
|
func SM2Decrypt(cipherText, publicKey string, privateKey string) (content string, err error) {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
err = fmt.Errorf("SM2Decrypt error: %v", r)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
if cipherText == "" {
|
if cipherText == "" {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,7 @@ func FastHttpGet(url string, header map[string]string, body map[string]string, t
|
||||||
resp := fasthttp.AcquireResponse()
|
resp := fasthttp.AcquireResponse()
|
||||||
defer fasthttp.ReleaseResponse(resp) // 用完需要释放资源
|
defer fasthttp.ReleaseResponse(resp) // 用完需要释放资源
|
||||||
var err error
|
var err error
|
||||||
if timeout == 0 {
|
if timeout <= 0 {
|
||||||
if err = fasthttp.Do(req, resp); err != nil {
|
if err = fasthttp.Do(req, resp); err != nil {
|
||||||
utils.Log(nil, "http请求失败", err, url)
|
utils.Log(nil, "http请求失败", err, url)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Reference in New Issue