main
elf 8 months ago
parent 2e651ca330
commit 0a66dfa6f3

@ -103,7 +103,7 @@ func Order(c *gin.Context) (utils.Data, error) {
}
func GetWxAuthUrl(c *gin.Context) (utils.Data, error) {
authUrl := weixin.WxApi.GetAuthUrl("")
authUrl := weixin.WxApi.GetAuthUrl("https://www.baidu.com")
data := utils.Data{"url": authUrl}
return data, nil
}

@ -1,7 +0,0 @@
package config
type Alipay struct {
AppId string `yaml:"app-id"`
PrivateKey string `yaml:"private-key"`
AliPublicKey string `yaml:"ali-public-key"`
}

@ -3,7 +3,6 @@ package config
type Config struct {
Server Server
Database Database
Alipay Alipay
Jwt Jwt
Redis Redis
Payment Payment

@ -1,13 +1,13 @@
package config
type Payment struct {
BaseUrl string
AppKey string
SignKey string
WxPay WxPay
BaseUrl string `yaml:"base-url"`
ApiKey string `yaml:"api-key"`
SignKey string `yaml:"sign-key"`
WxPay WxPay `yaml:"wx-pay"`
}
type WxPay struct {
SubAppId string
SubAppSecret string
SubAppId string `yaml:"sub-app-id"`
SubAppSecret string `yaml:"sub-app-secret"`
}

@ -7,6 +7,7 @@ import (
"gopkg.in/yaml.v3"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"os"
)
@ -28,7 +29,11 @@ func InitConfig() *config.Config {
}
func InitDB(conf *config.Config) *gorm.DB {
db, err := gorm.Open(mysql.Open(conf.Database.GetDsn()), &gorm.Config{})
var mysqlLogger logger.Interface
mysqlLogger = logger.Default.LogMode(logger.Info)
db, err := gorm.Open(mysql.Open(conf.Database.GetDsn()), &gorm.Config{
Logger: mysqlLogger,
})
if err != nil {
panic(err)
}

@ -16,7 +16,7 @@ import (
)
func main() {
payOrderCommon()
RunServer()
}
func RunServer() {

@ -22,9 +22,9 @@ func h5RouteInit(r *gin.Engine) {
authGroup.GET("/ping", utils.JsonHandler(api.Index))
authGroup.GET("/error", utils.JsonHandler(api.Error))
authGroup.GET("/get-user-info", utils.JsonHandler(api.GetUserInfo))
authGroup.GET("/order", utils.JsonHandler(api.Order))
authGroup.GET("/modify-password", utils.JsonHandler(api.ModifyPassword))
authGroup.GET("/payment", utils.JsonHandler(api.Payment))
authGroup.POST("/order", utils.JsonHandler(api.Order))
authGroup.POST("/modify-password", utils.JsonHandler(api.ModifyPassword))
authGroup.POST("/payment", utils.JsonHandler(api.Payment))
authGroup.GET("/get-wx-open-id", utils.JsonHandler(api.GetWxOpenId))
authGroup.GET("/get-wx-auth-url", utils.JsonHandler(api.GetWxAuthUrl))
}

@ -17,7 +17,7 @@ type orderService struct {
func (orderService) Order(orderRequest request.OrderRequest, user *model.User) (*model.Order, error) {
product := &model.Product{}
err := global.DB.Where("product_id", orderRequest.ProductID).First(product).Error
err := global.DB.Where("id", orderRequest.ProductID).First(product).Error
if e.Is(err, gorm.ErrRecordNotFound) {
return nil, errors.NewBusinessError("商品不存在")
}

@ -21,7 +21,7 @@ func (api *payApi) WxPay(param WxPayParam) (*WxPayResult, error) {
payment := global.Config.Payment
data := url.Values{}
data.Set("service", "comm.js.pay")
data.Set("apikey", payment.AppKey)
data.Set("apikey", payment.ApiKey)
data.Set("money", fmt.Sprintf("%.2f", param.Amount))
data.Set("sub_appid", payment.WxPay.SubAppId)
data.Set("sub_openid", param.OpenId)

@ -1,6 +1,8 @@
package weixin
type AccessTokenResult struct {
ErrorCode int `json:"errcode"`
ErrorMessage string `json:"errmsg"`
AccessToken string `json:"access_token"`
ExpiresIn int `json:"expires_in"`
RefreshToken string `json:"refresh_token"`

@ -32,10 +32,14 @@ func (api wxApi) GetAccessToken(code string) (*AccessTokenResult, error) {
if err != nil {
return nil, errors.NewBusinessError("数据解析错误")
}
if result.ErrorCode != 200 {
return nil, errors.NewBusinessError(result.ErrorMessage)
}
return &result, nil
}
func (api wxApi) GetAuthUrl(redirectUrl string) string {
fmt.Println(global.Config)
params := url.Values{}
params.Set("appid", global.Config.Payment.WxPay.SubAppId)
params.Set("redirect_uri", redirectUrl)

Loading…
Cancel
Save