基础整理
This commit is contained in:
+72
-39
@@ -3,50 +3,17 @@ package app
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
"code.hoteas.com/golang/hotime/dri/ddsms"
|
||||
"github.com/silenceper/wechat/v2"
|
||||
"github.com/silenceper/wechat/v2/cache"
|
||||
"github.com/silenceper/wechat/v2/miniprogram"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/config"
|
||||
"github.com/silenceper/wechat/v2/officialaccount"
|
||||
h5config "github.com/silenceper/wechat/v2/officialaccount/config"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Project 管理端项目
|
||||
var Project = Proj{
|
||||
"salesman": Salesman,
|
||||
"lxcx": Lxcx,
|
||||
"wechat": Wechat,
|
||||
"websocket": WebsocketCtr,
|
||||
}
|
||||
var weixin *wechat.Wechat //微信登录实例
|
||||
var miniProgram *miniprogram.MiniProgram
|
||||
var h5Program *officialaccount.OfficialAccount
|
||||
|
||||
func InitApp(app *Application) {
|
||||
weixin = wechat.NewWechat()
|
||||
memory := cache.NewMemory()
|
||||
memoryMini := cache.NewMemory()
|
||||
cfg := &config.Config{
|
||||
AppID: app.Config.GetString("wechatMiniAppID"),
|
||||
AppSecret: app.Config.GetString("wechatMiniAppSecret"),
|
||||
//Token: "xxx",
|
||||
//EncodingAESKey: "xxxx",
|
||||
Cache: memoryMini,
|
||||
}
|
||||
h5cfg := &h5config.Config{
|
||||
AppID: app.Config.GetString("wechatAppID"),
|
||||
AppSecret: app.Config.GetString("wechatAppSecret"),
|
||||
//Token: "xxx",
|
||||
//EncodingAESKey: "xxxx",
|
||||
Cache: memory,
|
||||
}
|
||||
|
||||
miniProgram = weixin.GetMiniProgram(cfg)
|
||||
h5Program = weixin.GetOfficialAccount(h5cfg)
|
||||
|
||||
ddsms.DDY.Init(app.Config.GetString("smsKey"))
|
||||
"lxcx": Lxcx,
|
||||
"websocket": WebsocketCtr,
|
||||
"wechath5": Wechath5,
|
||||
"wechatmini": Wechath5,
|
||||
"provider": ProviderCtr,
|
||||
}
|
||||
|
||||
//生成随机码的6位md5
|
||||
@@ -63,3 +30,69 @@ func getCode() string {
|
||||
//}
|
||||
return res
|
||||
}
|
||||
|
||||
//认证公共方案
|
||||
func auth(that *Context, phone, companyName string) error {
|
||||
|
||||
user := that.Db.Get("user", "id,phone,salesman_id,company_id,provider_id", Map{"id": that.Session("user_id").ToCeilInt()})
|
||||
if user == nil {
|
||||
return errors.New("找不到用户")
|
||||
}
|
||||
|
||||
//手机号与原来的不同则进行绑定
|
||||
if phone != user.GetString("phone") {
|
||||
//微信验证成功
|
||||
if that.Session("wechat_phone").ToStr() == phone {
|
||||
that.Db.Update("user", Map{"phone": phone}, Map{"id": user.GetCeilInt("id")})
|
||||
if user.GetCeilInt("company_id") != 0 {
|
||||
that.Db.Update("company", Map{"phone": phone}, Map{"id": user.GetCeilInt("company_id")})
|
||||
}
|
||||
user["phone"] = phone
|
||||
} else if that.Req.FormValue("code") == "" || that.Session("phone").ToStr() != phone || that.Session("code").ToStr() != that.Req.FormValue("code") {
|
||||
|
||||
return errors.New("验证码错误")
|
||||
} else {
|
||||
that.Db.Update("user", Map{"phone": phone}, Map{"id": user.GetCeilInt("id")})
|
||||
if user.GetCeilInt("company_id") != 0 {
|
||||
that.Db.Update("company", Map{"phone": phone}, Map{"id": user.GetCeilInt("company_id")})
|
||||
}
|
||||
user["phone"] = phone
|
||||
}
|
||||
|
||||
}
|
||||
//
|
||||
company := that.Db.Get("company", "name,id", Map{"id": user.GetCeilInt("company_id")})
|
||||
if company != nil {
|
||||
that.Db.Update("company", Map{"name": companyName}, Map{"id": company.GetCeilInt64("id")})
|
||||
if user.GetCeilInt64("salesman_id") != 0 {
|
||||
that.Db.Update("user", Map{"certification_flag": 1}, Map{"id": user.GetCeilInt("id")})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
company = Map{"name": companyName,
|
||||
"user_id": user.GetCeilInt("id"),
|
||||
}
|
||||
if user.GetCeilInt("salesman_id") != 0 {
|
||||
company["salesman_id"] = user.GetCeilInt("salesman_id")
|
||||
}
|
||||
if user.GetCeilInt("provider_id") != 0 {
|
||||
company["provider_id"] = user.GetCeilInt("provider_id")
|
||||
}
|
||||
if user.GetString("phone") != "" {
|
||||
company["phone"] = user.GetString("phone")
|
||||
}
|
||||
company["id"] = that.Db.Insert("company", company)
|
||||
if company.GetCeilInt64("id") == 0 {
|
||||
return errors.New("新建企业失败")
|
||||
}
|
||||
upUser := Map{"company_id": company.GetCeilInt64("id")}
|
||||
if user.GetCeilInt64("salesman_id") != 0 {
|
||||
upUser["certification_flag"] = 1
|
||||
|
||||
}
|
||||
that.Db.Update("user", upUser, Map{"id": that.Session("user_id").Data})
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user