Merge branch 'jdshop' of https://e.coding.net/rosydev/jx-callback into jdshop

This commit is contained in:
richboo111
2023-01-31 11:01:28 +08:00
16 changed files with 331 additions and 47 deletions

View File

@@ -33,12 +33,13 @@ const (
)
const (
AuthTypeNone = ""
AuthTypePassword = "localpass"
AuthTypeEmail = "email"
AuthTypeMobile = "mobile"
AuthTypeWXApp = "weixinapp" //微信小程序
AuthTypeWXMini = "weixinmini" //微信小程序
AuthTypeNone = ""
AuthTypePassword = "localpass"
AuthTypeEmail = "email"
AuthTypeMobile = "mobile"
AuthTypeWXApp = "weixinapp" //微信小程序(商家版)
AuthTypeWXAppCaishi = "weixinappcs" //微信小程序(用户)
AuthTypeWXMini = "weixinmini" //微信小程序
)
const (
@@ -305,7 +306,7 @@ func LoginInternal(ctx *Context, authType, authID, authIDType, authSecret string
}
}
//微信APP端登录
if authType == AuthTypeWXApp {
if authType == AuthTypeWXApp || authType == AuthTypeWXAppCaishi {
appID := strings.Split(authSecret, ",")[0]
if appID == model.JXC4ClientAppID && authInfo.AuthBindInfo.UserID != "" {
binds, err := dao.GetUserBindAuthInfo(dao.GetDB(), authInfo.AuthBindInfo.UserID, 0, nil, "", "", []string{model.JXC4ClientAppID})
@@ -335,7 +336,7 @@ func Login(ctx *Context, authType, authID, authIDType, authSecret string) (authI
return LoginInternal(ctx, authType, authID, authIDType, authSecret)
}
// 抖音用户信息解密
// TikTokDecryptInfo 抖音用户信息解密
type TikTokDecryptInfo struct {
CountryCode string `json:"countryCode"`
PhoneNumber string `json:"phoneNumber"`
@@ -346,7 +347,13 @@ type TikTokDecryptInfo struct {
} `json:"watermark"`
}
func DecryptUserMsg(sessionKey, iv, msg string) (string, error) {
// KuaiShouInfo 抖音用户信息解密
type KuaiShouInfo struct {
CountryCode string `json:"countryCode"`
PhoneNumber string `json:"phoneNumber"`
}
func DecryptUserMsg(sessionKey, iv, msg, loginType string) (string, error) {
decodeMsg, err := base64.StdEncoding.DecodeString(msg)
if err != nil {
return "", err
@@ -364,11 +371,22 @@ func DecryptUserMsg(sessionKey, iv, msg string) (string, error) {
if err != nil {
return "", err
}
result := &TikTokDecryptInfo{}
if err := json.Unmarshal(userInfo, result); err != nil {
return "", err
switch loginType {
case "tiktokmini":
result := &TikTokDecryptInfo{}
if err := json.Unmarshal(userInfo, result); err != nil {
return "", err
}
return result.PhoneNumber, nil
case "kuaishoumini":
result := &KuaiShouInfo{}
if err := json.Unmarshal(userInfo, result); err != nil {
return "", err
}
return result.PhoneNumber, nil
}
return result.PhoneNumber, nil
return "", ErrIllegalAuthType
}
// 通过临时TOKEN绑定新创建的用户

View File

@@ -16,20 +16,20 @@ const (
AuthTypeTiktokMini = "tiktokmini" // 抖音小程序
)
type TiktopMiniAuther struct {
type TiktokMiniAuther struct {
authprovider.DefAuther
}
var (
AutherObjMini *TiktopMiniAuther
AutherObjMini *TiktokMiniAuther
)
func init() {
AutherObjMini = new(TiktopMiniAuther)
AutherObjMini = new(TiktokMiniAuther)
auth2.RegisterAuther(AuthTypeTiktokMini, AutherObjMini)
}
func (a *TiktopMiniAuther) VerifySecret(dummy, code string) (authBindEx *auth2.AuthBindEx, err error) {
func (a *TiktokMiniAuther) VerifySecret(dummy, code string) (authBindEx *auth2.AuthBindEx, err error) {
//appID, realCode := splitCode(code)
//sessionInfo, err := getTikTokApp(appID).GetTiktokOauth(realCode)
sessionInfo, err := api.TiktokApi.GetTiktokOauth(code)
@@ -44,7 +44,7 @@ func (a *TiktopMiniAuther) VerifySecret(dummy, code string) (authBindEx *auth2.A
}
// 特殊接口
func (a *TiktopMiniAuther) DecryptData(authInfo *auth2.AuthInfo, jsCode, encryptedData, iv string) (decryptedDataBase64 string, err error) {
func (a *TiktokMiniAuther) DecryptData(authInfo *auth2.AuthInfo, jsCode, encryptedData, iv string) (decryptedDataBase64 string, err error) {
var sessionKey string
appID, jsCode := weixin.SplitJsCode(jsCode)
if jsCode != "" {
@@ -74,7 +74,7 @@ func (a *TiktopMiniAuther) DecryptData(authInfo *auth2.AuthInfo, jsCode, encrypt
return string(decryptedData), nil
}
func (a *TiktopMiniAuther) GetUserType() (userType int8) {
func (a *TiktokMiniAuther) GetUserType() (userType int8) {
return model.UserTypeStoreBoss
}

View File

@@ -0,0 +1,100 @@
package kuaishou
import (
"git.rosy.net.cn/jx-callback/business/auth2"
"git.rosy.net.cn/jx-callback/business/auth2/authprovider"
"git.rosy.net.cn/jx-callback/globals/api"
)
const (
AuthTypeKuaiShouMini = "kuaishoumini" // 快手小程序
)
type KuaiShouMiniAuther struct {
authprovider.DefAuther
}
var (
AutherObjMini *KuaiShouMiniAuther
)
func init() {
AutherObjMini = new(KuaiShouMiniAuther)
auth2.RegisterAuther(AuthTypeKuaiShouMini, AutherObjMini)
}
func (a *KuaiShouMiniAuther) VerifySecret(dummy, code string) (authBindEx *auth2.AuthBindEx, err error) {
//appID, realCode := splitCode(code)
//sessionInfo, err := getTikTokApp(appID).GetTiktokOauth(realCode)
sessionInfo, openId, err := api.KuaiShouApi.AuthLoginKuaiShou(code)
if err != nil {
return nil, err
}
if authBindEx, err = a.UnionFindAuthBind(AuthTypeKuaiShouMini, api.KuaiShouApi.GetAppID(), []string{AuthTypeKuaiShouMini}, openId, "", sessionInfo); err == nil {
authBindEx.UserData = sessionInfo
}
return authBindEx, err
}
//func (a *KuaiShouMiniAuther) DecryptData(authInfo *auth2.AuthInfo, jsCode, encryptedData, iv string) (decryptedDataBase64 string, err error) {
// var sessionKey string
// appID, jsCode := weixin.SplitJsCode(jsCode)
// if jsCode != "" {
// sessionInfo, err := getWxApp(appID).SNSCode2Session(jsCode)
// if err == nil {
// // if authBindEx, err := a.UnionFindAuthBind(AuthTypeMini, getWxApp(appID).GetAppID(), []string{AuthTypeMini}, sessionInfo.OpenID, "", nil); err == nil {
// // if authBindEx.UserID != authInfo.GetID() {
// // return "", fmt.Errorf("jsCode与token不匹配")
// // }
// // } else {
// // return "", err
// // }
// sessionKey = sessionInfo.SessionKey
// } else {
// return "", err
// }
// } else {
// if authInfo.AuthBindInfo.Type != AuthTypeKuaiShouMini {
// // return "", ErrAuthTypeShouldBeMini
// }
// sessionKey = authInfo.AuthBindInfo.UserData.(string)
// }
// decryptedData, err := weixinapi.SNSDecodeMiniProgramData(encryptedData, sessionKey, iv)
// if err != nil {
// return "", err
// }
// return string(decryptedData), nil
//}
//
//func (a *KuaiShouMiniAuther) GetUserType() (userType int8) {
// return model.UserTypeStoreBoss
//}
//
//func getWxApp(appID string) (miniApi *weixinapi.API) {
// miniApi = api.WeixinMiniAPI
// if len(appID) > 0 && appID == api.WeixinMiniAppID2 {
// miniApi = api.WeixinMiniAPI2
// }
// if len(appID) > 0 && appID == api.WeixinMiniAppIDsc {
// miniApi = api.WeixinMiniAPIsc
// }
// return miniApi
//}
//
//func getTikTokApp(appID string) (TikTokMini *tiktok.API) {
// TikTokMini = api.TiktokApi
// if len(appID) > 0 && appID == api.TiktokJXDJApiID {
// TikTokMini = api.TiktokJXDJApi
// }
// return TikTokMini
//}
//func splitCode(code string) (appID, realCode string) {
// str := strings.Split(code, "&")
// if len(str) == 2 {
// appID = str[1]
// realCode = str[0]
// } else {
// globals.SugarLogger.Warnf("splitCode abnormal code:%s", code)
// }
// return appID, realCode
//}

View File

@@ -2,7 +2,6 @@ package weixin
import (
"errors"
"git.rosy.net.cn/baseapi/platformapi/weixinapi"
"git.rosy.net.cn/jx-callback/business/auth2"
"git.rosy.net.cn/jx-callback/business/auth2/authprovider"
@@ -11,10 +10,11 @@ import (
)
const (
AuthTypeWeixin = "wxqrcode" // 微信扫码
AuthTypeMP = "weixinsns" // 公众号
AuthTypeWXNative = "wxnative" // 微信APP
AuthTypeWxApp = "weixinapp" //app微信登录
AuthTypeWeixin = "wxqrcode" // 微信扫码
AuthTypeMP = "weixinsns" // 公众号
AuthTypeWXNative = "wxnative" // 微信APP
AuthTypeWxApp = "weixinapp" //app微信登录(商家版)
AuthTypeWxAppCaishi = "weixinappcs" //app微信登录(用户版)
)
type Auther struct {
@@ -23,10 +23,11 @@ type Auther struct {
}
var (
AutherObjWX *Auther
AutherObjMP *Auther
AutherObjNative *Auther
AutherObjApp *Auther
AutherObjWX *Auther
AutherObjMP *Auther
AutherObjNative *Auther
AutherObjApp *Auther
AutherObjCaiShiApp *Auther
)
var (
@@ -53,6 +54,11 @@ func init() {
authType: AuthTypeWxApp,
}
auth2.RegisterAuther(AuthTypeWxApp, AutherObjApp)
AutherObjCaiShiApp = &Auther{
authType: AuthTypeWxAppCaishi,
}
auth2.RegisterAuther(AuthTypeWxAppCaishi, AutherObjCaiShiApp)
}
func (a *Auther) VerifySecret(id, secret string) (authBindEx *auth2.AuthBindEx, err error) {
@@ -89,7 +95,7 @@ func (a *Auther) VerifySecret(id, secret string) (authBindEx *auth2.AuthBindEx,
if err == nil {
wxUserinfo, err2 := a.getAPI().SNSGetUserInfo(accessToken, openID)
if err = err2; err == nil {
if authBindEx, err = a.UnionFindAuthBind(a.authType, a.getAPI().GetAppID(), []string{AuthTypeWeixin, AuthTypeMP, AuthTypeMini, AuthTypeWXNative, AuthTypeWxApp}, wxUserinfo.OpenID, wxUserinfo.UnionID, wxUserinfo); err == nil {
if authBindEx, err = a.UnionFindAuthBind(a.authType, a.getAPI().GetAppID(), []string{AuthTypeWeixin, AuthTypeMP, AuthTypeMini, AuthTypeWXNative, AuthTypeWxApp, AuthTypeWxAppCaishi}, wxUserinfo.OpenID, wxUserinfo.UnionID, wxUserinfo); err == nil {
authBindEx.UserHint = &auth2.UserBasic{
Name: wxUserinfo.NickName,
Avatar: wxUserinfo.HeadImgURL,
@@ -107,6 +113,9 @@ func (a *Auther) getAPI() *weixinapi.API {
if a.authType == AuthTypeWxApp {
return api.WeixinApp
}
if a.authType == AuthTypeWxAppCaishi {
return api.WeixinApp2
}
return api.WeixinAPI
}

View File

@@ -3526,7 +3526,7 @@ func GetStoreCategoryMap(ctx *jxcontext.Context, parentID, level int, storeID in
if err != nil {
return nil, err
}
if ctx.GetLoginType() != weixin.AuthTypeMP && ctx.GetLoginType() != weixin.AuthTypeMini && ctx.GetLoginType() != weixin.AuthTypeWxApp && ctx.GetLoginType() != auth2.AuthTypeMobile {
if ctx.GetLoginType() != weixin.AuthTypeMP && ctx.GetLoginType() != weixin.AuthTypeMini && ctx.GetLoginType() != weixin.AuthTypeWxApp && ctx.GetLoginType() != weixin.AuthTypeWxAppCaishi && ctx.GetLoginType() != auth2.AuthTypeMobile {
return storeCatMaps, err
}
//表示没有门店分类
@@ -3542,7 +3542,7 @@ func GetStoreCategoryMapNoDefault(ctx *jxcontext.Context, parentID, level int, s
if err != nil {
return nil, err
}
if ctx.GetLoginType() != weixin.AuthTypeMP && ctx.GetLoginType() != weixin.AuthTypeMini && ctx.GetLoginType() != weixin.AuthTypeWxApp && ctx.GetLoginType() != auth2.AuthTypeMobile {
if ctx.GetLoginType() != weixin.AuthTypeMP && ctx.GetLoginType() != weixin.AuthTypeMini && ctx.GetLoginType() != weixin.AuthTypeWxApp && ctx.GetLoginType() != weixin.AuthTypeWxAppCaishi && ctx.GetLoginType() != auth2.AuthTypeMobile {
return storeCatMaps, err
}
return storeCatMaps, err
@@ -5512,7 +5512,7 @@ func GetBrandCategoryMap(ctx *jxcontext.Context, parentID, level int, brandID in
if err != nil {
return nil, err
}
if ctx.GetLoginType() != weixin.AuthTypeMP && ctx.GetLoginType() != weixin.AuthTypeMini && ctx.GetLoginType() != weixin.AuthTypeWxApp && ctx.GetLoginType() != auth2.AuthTypeMobile {
if ctx.GetLoginType() != weixin.AuthTypeMP && ctx.GetLoginType() != weixin.AuthTypeMini && ctx.GetLoginType() != weixin.AuthTypeWxApp && ctx.GetLoginType() != weixin.AuthTypeWxAppCaishi && ctx.GetLoginType() != auth2.AuthTypeMobile {
return brandCatMaps, err
}
return brandCatMaps, err

View File

@@ -5896,7 +5896,7 @@ func doStoreSkuAudit(ctx *jxcontext.Context, storeIDs []int, skuBindInfos []*Sto
return false, err
}
if ctx.GetLoginType() != weixin.AuthTypeMP && ctx.GetLoginType() != weixin.AuthTypeMini && ctx.GetLoginType() != weixin.AuthTypeWxApp && ctx.GetLoginType() != auth2.AuthTypeMobile {
if ctx.GetLoginType() != weixin.AuthTypeMP && ctx.GetLoginType() != weixin.AuthTypeMini && ctx.GetLoginType() != weixin.AuthTypeWxApp && ctx.GetLoginType() != weixin.AuthTypeWxAppCaishi && ctx.GetLoginType() != auth2.AuthTypeMobile {
authInfo, err := ctx.GetV2AuthInfo()
if err == nil && authInfo != nil && (ctx.GetFullUser().Type&model.UserTypeOperator) != 0 {
if len(storeAudits) > 0 {
@@ -5974,7 +5974,7 @@ func doStoreSkuAuditForGy(ctx *jxcontext.Context, storeIDs []int, skuBindInfos [
return false, err
}
if ctx.GetLoginType() != weixin.AuthTypeMP && ctx.GetLoginType() != weixin.AuthTypeMini && ctx.GetLoginType() != weixin.AuthTypeWxApp && ctx.GetLoginType() != auth2.AuthTypeMobile {
if ctx.GetLoginType() != weixin.AuthTypeMP && ctx.GetLoginType() != weixin.AuthTypeMini && ctx.GetLoginType() != weixin.AuthTypeWxApp && ctx.GetLoginType() != weixin.AuthTypeWxAppCaishi && ctx.GetLoginType() != auth2.AuthTypeMobile {
authInfo, err := ctx.GetV2AuthInfo()
if err == nil && authInfo != nil && (ctx.GetFullUser().Type&model.UserTypeOperator) != 0 {
if len(storeAudits) > 0 {

View File

@@ -504,7 +504,7 @@ func GetMyStoreListNew(ctx *jxcontext.Context, version string) (storesInfo inter
if !auth2.IsV2Token(ctx.GetToken()) {
return nil, model.ErrCodeTokenIsInvalid, model.ErrTokenIsInvalid
}
if ctx.GetLoginType() == weixin.AuthTypeWxApp {
if ctx.GetLoginType() == weixin.AuthTypeWxApp || ctx.GetLoginType() == weixin.AuthTypeWxAppCaishi {
if configs, _ := dao.QueryConfigs(dao.GetDB(), "checkversion", model.ConfigTypeSys, ""); len(configs) > 0 {
if version == "" || configs[0].Value != version {
return nil, "", fmt.Errorf("当前APP版本过旧数据显示有错误请到'京西菜市'公众号下载最新版本APP")

View File

@@ -2,6 +2,8 @@ package ddmsg
import (
"fmt"
"git.rosy.net.cn/jx-callback/business/jxutils/enterprise_msg"
"git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/baseapi/platformapi/dingdingapi"
"git.rosy.net.cn/baseapi/utils/errlist"
@@ -32,7 +34,14 @@ func SendUserMessage(msgType, userID, title, content string) (err error) {
if len(content) > dingdingapi.MaxWorkContentLen {
content = content[:dingdingapi.MaxWorkContentLen-4] + "..."
}
err = SendDDUserMessage(msgType, auth.AuthID, title, content)
if err := SendDDUserMessage(msgType, auth.AuthID, title, content); err != nil {
userInfo, err := dao.GetUserByID(dao.GetDB(), "user_id", auth.UserID)
if err != nil || userInfo == nil {
globals.SugarLogger.Errorf("get user err %v", err)
continue
}
enterprise_msg.SendUserMessage(*userInfo.Mobile, title, content, content)
}
break
}
}
@@ -43,6 +52,7 @@ func SendUserMessage(msgType, userID, title, content string) (err error) {
if err != nil {
globals.SugarLogger.Infof("SendUserMessage userID:%s, title:%s, content:%s failed with error:%v", userID, title, content, err)
}
return err
}

View File

@@ -0,0 +1,110 @@
package enterprise_msg
import (
enterprise "git.rosy.net.cn/baseapi/platformapi/enterprise_wechat"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
)
var enterpriseUserIdMap = map[string]string{
"15881105234": "WenShiQi",
"15928865396": "HeJiaMeng2",
"18981810340": "LiuLei",
"18048531223": "ShiFeng2",
"18080188338": "ShiFeng",
"18744776542": "WuTingQi",
"15729837802": "ZhangShuWei",
"17358644830": "ShengTianBanZi1376",
"18982250714": "LaoZhaoTongXue",
"15680070110": "LiRongWei",
"18780171617": "TianQinXin",
"17381914617": "TianQinXin2",
"18583684218": "JingXiCaiShi-YanXiaoKang18583684218",
"17381580510": "YouRan",
}
// SendUserMessage 发送文本卡片
func SendUserMessage(phone, title, description, url string) error {
// 根据电话号码获取用户touserId
var enterpriseUserId = ""
var err error = nil
if id, ok := enterpriseUserIdMap[phone]; ok {
enterpriseUserId = id
} else {
enterpriseUserId, err = api.EnterpriseChatMin.GetUserIdByMobile(phone)
if err != nil {
enterpriseUserId = enterpriseUserIdMap["18981810340"]
}
enterpriseUserIdMap[phone] = enterpriseUserId
}
err = api.EnterpriseChatMin.SendMsgToUserTypeText(&enterprise.SendTextMsgReq{
Touser: enterpriseUserId,
Msgtype: enterprise.MsgTypeText,
Agentid: enterprise.EnterpriseAgentid,
Text: struct {
Content string `json:"content"`
}{Content: title + ":" + description},
Safe: 0,
EnableIdTrans: 0,
EnableDuplicateCheck: 0,
DuplicateCheckInterval: 0,
})
return err
//
//msg := &enterprise.EnterpriseSendMsgReq{
// Touser: enterpriseUserId,
// Msgtype: enterprise.MsgTypeTextCard,
// Agentid: enterprise.EnterpriseAgentid,
// Textcard: enterprise.TextCardObject{
// Title: title,
// Description: description,
// Url: url,
// Btntxt: "详情",
// },
//}
//return api.EnterpriseChatMin.SendMsgToUser(msg)
}
// SendUserMessageText 发送文本消息
func SendUserMessageText() {
}
func SendEnterpriseUserMessage(msgType, phone, title, content string) (err error) {
// 根据电话号码获取用户touserId
enterpriseUserId, err := api.EnterpriseChatMin.GetUserIdByMobile(phone)
if err != nil {
globals.SugarLogger.Errorf("SendEnterpriseUserMessage err1 %v", err)
return err
}
if msgType == enterprise.MsgTypeText {
err = api.EnterpriseChatMin.SendMsgToUserTypeText(&enterprise.SendTextMsgReq{
Touser: enterpriseUserId,
Msgtype: enterprise.MsgTypeText,
Agentid: enterprise.EnterpriseAgentid,
Text: struct {
Content string `json:"content"`
}{Content: title + ":" + content},
Safe: 0,
EnableIdTrans: 0,
EnableDuplicateCheck: 0,
DuplicateCheckInterval: 0,
})
} else if msgType == enterprise.MsgTypeMarkdown {
err = api.EnterpriseChatMin.SendMsgToUserMarkdown(&enterprise.SendMarkdownMsgReq{
Touser: enterpriseUserId,
Msgtype: enterprise.MsgTypeMarkdown,
Agentid: enterprise.EnterpriseAgentid,
Markdown: struct {
Content string `json:"content"`
}{Content: title + ":" + content},
Safe: 0,
EnableIdTrans: 0,
EnableDuplicateCheck: 0,
DuplicateCheckInterval: 0,
})
}
globals.SugarLogger.Errorf("SendEnterpriseUserMessage err2 %v", err)
return err
}

View File

@@ -2,6 +2,7 @@ package msg
import (
"fmt"
"git.rosy.net.cn/jx-callback/business/jxutils/enterprise_msg"
"git.rosy.net.cn/jx-callback/business/jxutils/ddmsg"
"git.rosy.net.cn/jx-callback/business/jxutils/weixinmsg"
@@ -30,7 +31,12 @@ func SendUserMessage(msgType string, user *model.User, title, content string) (e
if title != "" {
content = title + "\n" + content
}
err = ddmsg.SendDDUserMessage(msgType, auth.AuthID, title, content)
if err2 := ddmsg.SendDDUserMessage(msgType, auth.AuthID, title, content); err2 != nil {
if msgType == "txt" {
msgType = "text"
}
err = enterprise_msg.SendEnterpriseUserMessage(msgType, auth.AuthID, title, content)
}
} else if auth.Type == weixin.AuthTypeMP && msgType != dingdingapi.MsgTypeMarkdown {
err = weixinmsg.NotifyStoreStatusChanged(auth.AuthID, title, content)
}

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"git.rosy.net.cn/baseapi/platformapi/dingdingapi"
"git.rosy.net.cn/jx-callback/business/jxutils/ddmsg"
"git.rosy.net.cn/jx-callback/business/jxutils/enterprise_msg"
"strings"
"sync"
"time"
@@ -508,7 +509,12 @@ func SendMessage(t *BaseTask) {
} else {
content += ",\n" + t.Error()
}
ddmsg.SendUserMessage(dingdingapi.MsgTyeText, authInfo.UserID, "异步任务完成", content)
if err := ddmsg.SendUserMessage(dingdingapi.MsgTyeText, authInfo.UserID, "异步任务完成", content); err != nil {
globals.SugarLogger.Errorf("==============errr ddd %v", err)
err2 := enterprise_msg.SendUserMessage(authInfo.Mobile, "异步任务完成", "", content)
globals.SugarLogger.Errorf("==============errr ddd %v", err2)
}
}
}
}