diff --git a/Makefile b/Makefile index 6853e57..e7e8ea3 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,9 @@ build-sqlite: #docker: # docker build . -t go-admin:latest +demo: + GOOS=linux GOARCH=amd64 go build -o demo_hm_server main.go + dev: GOOS=linux GOARCH=amd64 go build -o dev_hm_server main.go diff --git a/config/config.go b/config/config.go index 573161c..e0101b5 100644 --- a/config/config.go +++ b/config/config.go @@ -11,7 +11,8 @@ import ( type config struct { Env string - ServerPort int + ServerPort int + ServerClientIp string JwtUserAccessKey string JwtUserRefreshKey string @@ -60,8 +61,6 @@ type config struct { RedisPassword string RedisDB int - //LotteryHost string - //LotteryPort int XianMaiBaseUrl string } @@ -102,7 +101,8 @@ func initConfig() { AppConfig = config{ Env: viper.GetString("ENV"), - ServerPort: viper.GetInt("server.port"), + ServerPort: viper.GetInt("server.port"), + ServerClientIp: viper.GetString("server.client_ip"), JwtUserAccessKey: viper.GetString("jwt.user.access_key"), JwtUserRefreshKey: viper.GetString("jwt.user.refresh_key"), @@ -129,10 +129,7 @@ func initConfig() { WxAppSecret: viper.GetString("wx.app_secret"), WxMchID: viper.GetString("wx.app_mchId"), WxMchSecret: viper.GetString("wx.app_mchSecret"), - //WxCertFile: viper.GetString("wx.wx_pay.cert_file"), - //WxKeyFile: viper.GetString("wx.wx_pay.key_file"), - //WxRootCaFile: viper.GetString("wx.wx_pay.root_ca_file"), - //WxPayCallBackUrl: viper.GetString("wx.wx_pay.callback_url"), + WxCertFile: viper.GetString("wx_pay.cert_file"), WxKeyFile: viper.GetString("wx_pay.key_file"), WxRootCaFile: viper.GetString("wx_pay.root_ca_file"), @@ -156,5 +153,5 @@ func initConfig() { XianMaiBaseUrl: viper.GetString("xianmai_base_url"), } - //fmt.Printf("%+v", AppConfig) + fmt.Printf("%+v", AppConfig) } diff --git a/lib/utils/crypt/crypt.go b/lib/utils/crypt/crypt.go index fb5b995..396bcab 100644 --- a/lib/utils/crypt/crypt.go +++ b/lib/utils/crypt/crypt.go @@ -22,6 +22,7 @@ import ( ) const AppletCodeBaseUrl = "http://switch.deovo.com:8000/img/applet_code/" +const AppletcodebaseurlDev = "http://dev.switch.deovo.com:8000/img/applet_code/" func GetWxAccessToken(appId, secret string) string { //https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET @@ -182,7 +183,7 @@ func GenDrawShareCode(Did string, appId, secret string, userID ...uint32) (strin logger.Error("err:", err) } //jpeg.Encode(f, resp, nil) //写入文件 - return AppletCodeBaseUrl + fileName, nil + return AppletcodebaseurlDev + fileName, nil } return "", errors.New(fmt.Sprintf("%d%s", res.Errcode, res.Errmsg)) diff --git a/lib/wxpay/wx_pay.go b/lib/wxpay/wx_pay.go index 0374d34..13f21ad 100644 --- a/lib/wxpay/wx_pay.go +++ b/lib/wxpay/wx_pay.go @@ -37,8 +37,9 @@ import ( const ( //clientIp = "120.229.60.77" - clientIp = "39.108.188.218" - domain = "switch.deovo.com:8001" + demoClientIp = "112.33.14.191" // demo服务器ip地址 + clientIp = "39.108.188.218" + domain = "switch.deovo.com:8001" //wxPayNotifyUrl = "api/v1/wxpay/notice" wxPayNotifyUrl = "/api/v1/wxpay/notice" @@ -63,7 +64,7 @@ const ( HmPayApiUrl = "https://hmpay.sandpay.com.cn/gateway/api" ) -//web 微信支付 +// web 微信支付 func WebPay(orderId string, totalFee uint32, openId, profitSharing, attach, notifyUrl string) (*Sextuple, error) { now := time.Now().Local() strTime := fmt.Sprintf("%04d%02d%02d%02d%02d%02d", now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second()) @@ -97,7 +98,7 @@ func WebPay(orderId string, totalFee uint32, openId, profitSharing, attach, noti FeeType: "CNY", TotalFee: strconv.Itoa(int(totalFee)), //SpbillCreateIp: config.AppConfig.IP, - SpbillCreateIp: clientIp, + SpbillCreateIp: config.AppConfig.ServerClientIp, //NotifyUrl: "https://" + config.AppConfig.Domain + config.AppConfig.WxPayNotifyUrl, //NotifyUrl: "https://" + domain + wxPayNotifyUrl, //NotifyUrl: configInfo.NotifyUrl, @@ -893,17 +894,18 @@ const ( WxAppId = "wx806c079463b5b56c" WxAppSecret = "3d7335cf0b9fa1d70aa7eb079526ebf0" - WxAppMchId = "1609877389" - WxAppMchSecret = "DeovoMingHuiRengTianTang45675456" - WxCheckName = "NO_CHECK" - SpbilCreateIp = "39.108.188.218" - WxTransferUrl = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers" + WxAppMchId = "1609877389" + WxAppMchSecret = "DeovoMingHuiRengTianTang45675456" + WxCheckName = "NO_CHECK" + DemoSpbilCreateIp = "112.33.14.191" // demo服务器ip地址 + SpbilCreateIp = "39.108.188.218" + WxTransferUrl = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers" WxKeyFile = "./configs/merchant/apiclient_key.pem" WxRootCaFile = "./configs/merchant/apiclient_cert.pem" ) -//https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_2 +// https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_2 type WxTransferReq struct { XMLName xml.Name `xml:"xml"` //xml标签 MchAppid string `xml:"mch_appid" json:"mch_appid"` //微信分配的小程序ID,必须 @@ -930,7 +932,7 @@ type WxTransferResp struct { PaymentNo string `xml:"payment_no,CDATA"` } -//给用户打款 +// 给用户打款 func Transfer(amount uint32, openId, desc string) (*WxTransferResp, error) { tradeNO := GenTradeNo() nonce := GenRandStr(NonceStringLength) @@ -946,7 +948,7 @@ func Transfer(amount uint32, openId, desc string) (*WxTransferResp, error) { CheckName: WxCheckName, Amount: fmt.Sprintf("%d", amount), Desc: desc, - SpbillCreateIp: SpbilCreateIp, + SpbillCreateIp: config.AppConfig.ServerClientIp, } wxResp := WxTransferResp{} @@ -1122,7 +1124,7 @@ type HmPayUnifiedOrderRsp struct { Sign string `json:"sign"` } -//hm 微信支付 +// hm 微信支付 func HmJsPayUnifiedOrder(orderId string, totalFee uint32, openId, notifyUrl string) (*HmPayUnifiedOrderPayData, error) { now := time.Now().Local() strTime := fmt.Sprintf("%04d%02d%02d%02d%02d%02d", now.Year(), now.Month(), now.Day(), now.Hour(), @@ -1160,7 +1162,7 @@ func HmJsPayUnifiedOrder(orderId string, totalFee uint32, openId, notifyUrl stri Body: "服务费", MerAppId: WxAppId, MerBuyerId: openId, - CreateIp: clientIp, + CreateIp: config.AppConfig.ServerClientIp, CreateTime: strTime, ExpireTime: strExpireTime, //LimitPay: "NO_CREDIT", diff --git a/model/config.go b/model/config.go index 66be1b2..8fb730c 100644 --- a/model/config.go +++ b/model/config.go @@ -83,7 +83,7 @@ func MemberConfigInfo() ([]MemberConfig, error) { } func GetMemberConfig(level uint32, genre uint32) (*MemberConfig, error) { - if level == 3 { + if level == 3 { // 短期会员 level = 2 } if level == 2 && genre != 0 { // 判断是否为黄金短期会员 @@ -107,38 +107,38 @@ func GetMemberConfig(level uint32, genre uint32) (*MemberConfig, error) { return nil, errors.New("level err") } -// 会员费配置 - -//var ShortMemberConfigMap = map[uint32]*MemberConfig{ -// 201: { -// MemberLever: 2, -// MemberFee: 1, -// MemberDeposit: 3, -// CardMax: 1, -// }, -// 202: { -// MemberLever: 2, -// MemberFee: 2, -// MemberDeposit: 3, -// CardMax: 1, -// }, -//} - +// ShortMemberConfigMap 会员费配置 +// 测试,金额小 var ShortMemberConfigMap = map[uint32]*MemberConfig{ - 201: { //短期黄金会员-90天 + 201: { MemberLever: 2, - MemberFee: 19900, - MemberDeposit: 30000, + MemberFee: 1, + MemberDeposit: 1, CardMax: 1, }, - 202: { //短期黄金会员-180天 + 202: { MemberLever: 2, - MemberFee: 29900, - MemberDeposit: 30000, + MemberFee: 2, + MemberDeposit: 1, CardMax: 1, }, } +//var ShortMemberConfigMap = map[uint32]*MemberConfig{ +// 201: { //短期黄金会员-90天 +// MemberLever: 2, +// MemberFee: 19900, +// MemberDeposit: 30000, +// CardMax: 1, +// }, +// 202: { //短期黄金会员-180天 +// MemberLever: 2, +// MemberFee: 29900, +// MemberDeposit: 30000, +// CardMax: 1, +// }, +//} + type MemberVmConfig struct { MemberLever uint32 `json:"member_lever"` // 会员等级 MemberVm uint32 `json:"member_vm"` diff --git a/model/templete_msg.go b/model/templete_msg.go index 6bab785..3be0538 100644 --- a/model/templete_msg.go +++ b/model/templete_msg.go @@ -14,6 +14,7 @@ import ( ) const ( + // WxPublicAppId WxPublicAppSecret todo 待确认 WxPublicAppId = "wxfdb1c5654f681c7e" WxPublicAppSecret = "6e1908a71f31a80849ef0e59d90b7147" ) @@ -28,13 +29,6 @@ func AccessToken() (string, error) { Errmsg string `json:"errmsg"` }{} - //config.AppConfig.WxAppId = "wxfdb1c5654f681c7e" - //config.AppConfig.WxAppSecret = "6e1908a71f31a80849ef0e59d90b7147" - //config.AppConfig.WxAppId = "wx806c079463b5b56c" - //config.AppConfig.WxAppSecret = "cb125688bf4e482f66e8c46062d568fc" - - //fmt.Println("WxAppId:", config.AppConfig.WxAppId) - //fmt.Println("WxAppSecret:", config.AppConfig.WxAppSecret) fmt.Println("WxAppId:", WxPublicAppId) fmt.Println("WxAppSecret:", WxPublicAppSecret) if err := requests.GetAndParseJson("https://api.weixin.qq.com/cgi-bin/token", map[string]string{ @@ -64,13 +58,10 @@ func AppAccessToken() (string, error) { Errmsg string `json:"errmsg"` }{} - //config.AppConfig.WxAppId = "wxfdb1c5654f681c7e" - //config.AppConfig.WxAppSecret = "6e1908a71f31a80849ef0e59d90b7147" - config.AppConfig.WxAppId = "wx806c079463b5b56c" - config.AppConfig.WxAppSecret = "cb125688bf4e482f66e8c46062d568fc" + // 读取配置信息,不再硬编码 + //config.AppConfig.WxAppId = "wx806c079463b5b56c" + //config.AppConfig.WxAppSecret = "cb125688bf4e482f66e8c46062d568fc" - //fmt.Println("WxAppId:", config.AppConfig.WxAppId) - //fmt.Println("WxAppSecret:", config.AppConfig.WxAppSecret) fmt.Println("WxAppId:", config.AppConfig.WxAppId) fmt.Println("WxAppSecret:", config.AppConfig.WxAppSecret) if err := requests.GetAndParseJson("https://api.weixin.qq.com/cgi-bin/token", map[string]string{ diff --git a/model/user.go b/model/user.go index ff11f1f..67cb6c4 100644 --- a/model/user.go +++ b/model/user.go @@ -19,7 +19,7 @@ type User struct { Model Uid uint32 `json:"uid" gorm:"column:uid;unique_index"` - MemberLevel uint32 `json:"member_level"` // 会员等级 1-用户 2-黄金会员 4-白金会员 5-黑金会员 + MemberLevel uint32 `json:"member_level"` // 会员等级 1-用户 2-黄金会员 3-短期会员 4-白金会员 5-黑金会员 MemberGenre uint32 `json:"member_genre"` // 会员类型 MemberExpire time.Time `json:"member_expire"` // 会员到期时间 OpenMemberTime time.Time `json:"open_member_time"` // 开通会员 @@ -28,7 +28,7 @@ type User struct { WxAvatar string `json:"wx_avatar"` // 头像 WxOpenID string `json:"wx_open_id"` // 微信openid AppOpenID string `json:"app_open_id"` // - WxUnionID string `json:"wx_union_id"` // 微信uniodid + WxUnionID string `json:"wx_union_id"` // 微信unionId Tel string `json:"tel"` // 电话 Gender uint8 `json:"gender"` // 性别 City string `json:"city"` // 城市 diff --git a/pack/configs/demo/server.json b/pack/configs/demo/server.json new file mode 100644 index 0000000..f395c19 --- /dev/null +++ b/pack/configs/demo/server.json @@ -0,0 +1,67 @@ +{ + "server": { + "port": 8001, + "client_ip": "112.33.14.191" + }, + "jwt": { + "user": { + "access_key": "oOqYrhCNQRvVNAaEo4h4osoW", + "refresh_key": "oOqYrhCadQRvVNAaEo4h4osW", + "access_expire": 259200, + "refresh_expire": 360000 + }, + "admin": { + "access_key": "oOqYrhCcQRvVNAaEo4h4osoW", + "refresh_key": "oOqYahCadQRvVNAaEo4h4osW", + "access_expire": 3600, + "refresh_expire": 129600 + } + }, + "log": { + "path": "log_server", + "file": "server", + "level": 0 + }, + "db": { + "driver": "mysql", + "host": "112.33.14.191", + "port": 3306, + "user": "mh_demo", + "password": "kTGGtddsmGdYRbxP", + "db_name": "mh_demo" + }, + "wx": { + "app_id": "wxe1963282cfe4840c", + "app_secret": "27e4dd0c628168d781d8ee45a6415405", + "app_mchId": "1494954322", + "app_mchSecret": "6c9eozed9Hq0hmXPzh5QTcO1KwrJbG3z" + }, + "app": { + "app_id": "wxe1963282cfe4840c", + "app_secret": "27e4dd0c628168d781d8ee45a6415405", + "app_mchId": "1494954322", + "app_mchSecret": "6c9eozed9Hq0hmXPzh5QTcO1KwrJbG3z" + }, + "wx_pay": { + "callback_url": "https://demo.switch.deovo.com:9004/api/v1/wxpay_refund/notice", + "cert_file":"/Users/li/mh/mh_server/pack/configs/merchant/apiclient_cert.p12", + "key_file":"/Users/li/mh/mh_server/pack/configs/merchant/apiclient_key.pem", + "root_ca_file":"/Users/li/mh/mh_server/pack/configs/merchant/apiclient_cert.pem" + }, + "ali_pay": { + "callback_url": "" + }, + "sms": { + "access_key_id": "LTAI5atZsVv9y2MJ", + "access_key_secret": "shFlHKZDZshcAHJpwMYFojfoD7pQiX", + "sign_name": "明慧", + "template_code": "SMS_167675071" + }, + "redis": { + "host": "127.0.0.1", + "port": 6379, + "password": "", + "db": 100 + }, + "xianmai_base_url": "https://testh5.xianmai.net.cn" +} diff --git a/pack/configs/dev/server.json b/pack/configs/dev/server.json index 9a95303..98af85e 100644 --- a/pack/configs/dev/server.json +++ b/pack/configs/dev/server.json @@ -23,10 +23,10 @@ }, "db": { "driver": "mysql", - "host": "39.108.188.218", + "host": "112.33.14.191", "port": 3306, "user": "mh_dev", - "password": "m5h4parZsXjbeiFh", + "password": "d9qy46ONI0ZTF9eH", "db_name": "mh_dev" }, "wx": { @@ -63,4 +63,4 @@ "db": 100 }, "xianmai_base_url": "https://testh5.xianmai.net.cn" -} \ No newline at end of file +}