From eb8b84384e87b035026bd6b4538dedaee8aa3675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Mon, 30 Jan 2023 11:26:21 +0800 Subject: [PATCH] 1 --- .../douyin/{tiktop_mini.go => tiktok_mini.go} | 12 +- .../authprovider/kuaishou/kuaishou_mini.go | 109 ++++++++++++++++++ .../enterprise_msg/enterprise_send_msg.go | 29 ++++- controllers/auth2.go | 2 +- 4 files changed, 142 insertions(+), 10 deletions(-) rename business/auth2/authprovider/douyin/{tiktop_mini.go => tiktok_mini.go} (90%) create mode 100644 business/auth2/authprovider/kuaishou/kuaishou_mini.go diff --git a/business/auth2/authprovider/douyin/tiktop_mini.go b/business/auth2/authprovider/douyin/tiktok_mini.go similarity index 90% rename from business/auth2/authprovider/douyin/tiktop_mini.go rename to business/auth2/authprovider/douyin/tiktok_mini.go index 6306d3422..3647bbf7d 100644 --- a/business/auth2/authprovider/douyin/tiktop_mini.go +++ b/business/auth2/authprovider/douyin/tiktok_mini.go @@ -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 } diff --git a/business/auth2/authprovider/kuaishou/kuaishou_mini.go b/business/auth2/authprovider/kuaishou/kuaishou_mini.go new file mode 100644 index 000000000..af2b9d672 --- /dev/null +++ b/business/auth2/authprovider/kuaishou/kuaishou_mini.go @@ -0,0 +1,109 @@ +package kuaishou + +// +//import ( +// "git.rosy.net.cn/baseapi/platformapi/tiktok" +// "git.rosy.net.cn/baseapi/platformapi/weixinapi" +// "git.rosy.net.cn/jx-callback/business/auth2" +// "git.rosy.net.cn/jx-callback/business/auth2/authprovider" +// "git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin" +// "git.rosy.net.cn/jx-callback/business/model" +// "git.rosy.net.cn/jx-callback/globals" +// "git.rosy.net.cn/jx-callback/globals/api" +// "strings" +//) +// +//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, err := api.TiktokApi.GetTiktokOauth(code) +// if err != nil { +// return nil, err +// } +// sessionKey := sessionInfo.Data.SessionKey +// if authBindEx, err = a.UnionFindAuthBind(AuthTypeKuaiShouMini, api.TiktokApi.GetAppID(), []string{AuthTypeKuaiShouMini}, sessionInfo.Data.OpenId, sessionInfo.Data.Unionid, sessionInfo); err == nil { +// authBindEx.UserData = sessionKey +// } +// 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 +//} diff --git a/business/jxutils/enterprise_msg/enterprise_send_msg.go b/business/jxutils/enterprise_msg/enterprise_send_msg.go index f3f27a63c..a78ae4e1e 100644 --- a/business/jxutils/enterprise_msg/enterprise_send_msg.go +++ b/business/jxutils/enterprise_msg/enterprise_send_msg.go @@ -6,12 +6,35 @@ import ( "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", +} + // SendUserMessage 发送文本卡片 func SendUserMessage(phone, title, description, url string) error { // 根据电话号码获取用户touserId - enterpriseUserId, err := api.EnterpriseChatMin.GetUserIdByMobile(phone) - if err != nil { - return err + 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{ diff --git a/controllers/auth2.go b/controllers/auth2.go index 06ace309b..47df0f47b 100644 --- a/controllers/auth2.go +++ b/controllers/auth2.go @@ -104,7 +104,7 @@ func (c *Auth2Controller) TiktokDecrypt() { // @Title 登录接口 // @Description 登录接口(微信与公众号登录不能直接调用此接口) -// @Param authType formData string true "登录类型,当前支持[localpass:本地账号密码,mobile:手机短信,wxqrcode:微信登录,weixinsns:微信公众号,weixinmini;小程序,wxnative:微信APP,ddstaff:钉钉企业,ddqrcode:钉钉扫码,alipaycode:支付宝小程序]" +// @Param authType formData string true "登录类型,当前支持[kuaishou:快手授权登录,localpass:本地账号密码,mobile:手机短信,wxqrcode:微信登录,weixinsns:微信公众号,weixinmini;小程序,wxnative:微信APP,ddstaff:钉钉企业,ddqrcode:钉钉扫码,alipaycode:支付宝小程序]" // @Param authSecret formData string true "不同登录类型的登录秘密,如果是localpass登录类型,是md5后的值(空串不要md5)" // @Param authID formData string false "登录ID,登录类型为localpass时依赖于authIDType,其它为相应登录类型的id" // @Param authIDType formData string false "只有在登录类型为localpass时,才有意义,分别为:userid2:用户名,email,mobile"