Compare commits
No commits in common. "96aa3b16da7f7e666488a3af53ba061ca2ec48fd" and "99aa763357cb6c9f81a217eea5310f6ef1272330" have entirely different histories.
96aa3b16da
...
99aa763357
|
@ -52,10 +52,7 @@ const (
|
||||||
AppAesEncryptFail = 1234
|
AppAesEncryptFail = 1234
|
||||||
AppDeEncryptFail = 1250
|
AppDeEncryptFail = 1250
|
||||||
// 加密方式不存在
|
// 加密方式不存在
|
||||||
EncryptTypeNotFound = 1241
|
EncryptTypeNotFound = 1241
|
||||||
PayChannelConfigNotFound = 1242
|
|
||||||
// 加密参数异常
|
|
||||||
PayEncryptParamFail = 1243
|
|
||||||
|
|
||||||
//渠道
|
//渠道
|
||||||
PayChannelNotFound = 1300
|
PayChannelNotFound = 1300
|
||||||
|
@ -141,9 +138,7 @@ var MsgZH = map[int]string{
|
||||||
|
|
||||||
AppAesEncryptFail: "aes 加密失败",
|
AppAesEncryptFail: "aes 加密失败",
|
||||||
|
|
||||||
EncryptTypeNotFound: "加密方式不存在",
|
EncryptTypeNotFound: "加密方式不存在",
|
||||||
PayChannelConfigNotFound: "secret支付方式配置不存在",
|
|
||||||
PayEncryptParamFail: "加密参数错误,解析失败",
|
|
||||||
|
|
||||||
AppDeEncryptFail: "未知原因导致解密失败,请检查加密数据是和app加密配置",
|
AppDeEncryptFail: "未知原因导致解密失败,请检查加密数据是和app加密配置",
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,6 @@ 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"
|
||||||
|
@ -192,22 +190,22 @@ func BrokerWechatUrl(c *gin.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 首页
|
//// 首页
|
||||||
func Index(c *gin.Context) {
|
//func Ind/*ex(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)
|
||||||
code := services.GetWxAuth(*req)
|
// //openId, code := services.GetWxAuth(*req)
|
||||||
controllers.HandCodeRes(c, code, code)
|
// //controllers.HandCodeRes(c, openId, 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.PayEncryptParamFail
|
a.Code = errorcode.ParamError
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if requestCommonData.AppId != requestData.AppId || requestCommonData.Timestamp != requestData.Timestamp {
|
if requestCommonData.AppId != requestData.AppId || requestCommonData.Timestamp != requestData.Timestamp {
|
||||||
|
|
|
@ -2,14 +2,11 @@ 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/utils"
|
"PaymentCenter/app/third/paymentService"
|
||||||
"PaymentCenter/app/utils/httpclient"
|
|
||||||
"PaymentCenter/config"
|
"PaymentCenter/config"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
@ -50,7 +47,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) {
|
||||||
|
|
||||||
// 获取支付渠道的配置
|
// 获取支付渠道的配置
|
||||||
|
@ -65,35 +62,19 @@ func GetWxAuth(param front.GetWxAuthRequest) (code int) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//// 配置解析
|
// 配置解析
|
||||||
wxConfig := make(map[string]interface{})
|
wxConfig := paymentService.WxPay{}
|
||||||
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,
|
||||||
sk,
|
// wxConfig.SerialNo,
|
||||||
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,13 +56,7 @@ 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) (content string, err error) {
|
func SM2Decrypt(cipherText, publicKey string, privateKey string) (string, 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