From bd27c16c38f4795a6574dd671652165c51a22b62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Sun, 29 Jan 2023 14:43:32 +0800 Subject: [PATCH 01/17] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BC=81=E4=B8=9A?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=B6=88=E6=81=AF=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../enterprise_msg/enterprise_send_msg.go | 27 +++++++++++++++++++ business/jxutils/tasksch/task.go | 5 +++- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 business/jxutils/enterprise_msg/enterprise_send_msg.go diff --git a/business/jxutils/enterprise_msg/enterprise_send_msg.go b/business/jxutils/enterprise_msg/enterprise_send_msg.go new file mode 100644 index 000000000..bf37ab428 --- /dev/null +++ b/business/jxutils/enterprise_msg/enterprise_send_msg.go @@ -0,0 +1,27 @@ +package enterprise_msg + +import ( + enterprise "git.rosy.net.cn/baseapi/platformapi/enterprise_wechat" + "git.rosy.net.cn/jx-callback/globals/api" +) + +func SendUserMessage(phone, title, description, url string) error { + // 根据电话号码获取用户touserId + enterpriseUserId, err := api.EnterpriseChatMin.GetUserIdByMobile(phone) + if err != nil { + return err + } + + msg := &enterprise.EnterpriseSendMsgReq{ + Touser: enterpriseUserId, + Msgtype: enterprise.MsgTypeTextCard, + Agentid: 1000005, + Textcard: enterprise.TextCardObject{ + Title: title, + Description: description, + Url: url, + Btntxt: "详情", + }, + } + return api.EnterpriseChatMin.SendMsgToUser(msg) +} diff --git a/business/jxutils/tasksch/task.go b/business/jxutils/tasksch/task.go index bb04f2c5a..f8edc2c5b 100644 --- a/business/jxutils/tasksch/task.go +++ b/business/jxutils/tasksch/task.go @@ -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,9 @@ 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 { + enterprise_msg.SendUserMessage(authInfo.Mobile, "异步任务完成", "", content) + } } } } From 69ac19b7cc7e82f5d698f3759384f3f1794aedf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Sun, 29 Jan 2023 15:38:17 +0800 Subject: [PATCH 02/17] 1 --- business/jxutils/ddmsg/ddmsg.go | 12 ++++- .../enterprise_msg/enterprise_send_msg.go | 44 ++++++++++++++++++- business/jxutils/msg/msg.go | 8 +++- 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/business/jxutils/ddmsg/ddmsg.go b/business/jxutils/ddmsg/ddmsg.go index 258f80d94..a4d60e0d5 100644 --- a/business/jxutils/ddmsg/ddmsg.go +++ b/business/jxutils/ddmsg/ddmsg.go @@ -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) + } 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 } diff --git a/business/jxutils/enterprise_msg/enterprise_send_msg.go b/business/jxutils/enterprise_msg/enterprise_send_msg.go index bf37ab428..f6468ca2d 100644 --- a/business/jxutils/enterprise_msg/enterprise_send_msg.go +++ b/business/jxutils/enterprise_msg/enterprise_send_msg.go @@ -5,6 +5,7 @@ import ( "git.rosy.net.cn/jx-callback/globals/api" ) +// SendUserMessage 发送文本卡片 func SendUserMessage(phone, title, description, url string) error { // 根据电话号码获取用户touserId enterpriseUserId, err := api.EnterpriseChatMin.GetUserIdByMobile(phone) @@ -15,7 +16,7 @@ func SendUserMessage(phone, title, description, url string) error { msg := &enterprise.EnterpriseSendMsgReq{ Touser: enterpriseUserId, Msgtype: enterprise.MsgTypeTextCard, - Agentid: 1000005, + Agentid: enterprise.EnterpriseAgentid, Textcard: enterprise.TextCardObject{ Title: title, Description: description, @@ -25,3 +26,44 @@ func SendUserMessage(phone, title, description, url string) error { } 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 { + 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, + }) + } + return err +} diff --git a/business/jxutils/msg/msg.go b/business/jxutils/msg/msg.go index 6b961680d..937f168ee 100644 --- a/business/jxutils/msg/msg.go +++ b/business/jxutils/msg/msg.go @@ -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) } From 272876ba0170fc03da549beef9a02a273034b732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Sun, 29 Jan 2023 15:44:26 +0800 Subject: [PATCH 03/17] 1 --- business/jxutils/enterprise_msg/enterprise_send_msg.go | 3 +++ business/jxutils/tasksch/task.go | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/business/jxutils/enterprise_msg/enterprise_send_msg.go b/business/jxutils/enterprise_msg/enterprise_send_msg.go index f6468ca2d..629f08a76 100644 --- a/business/jxutils/enterprise_msg/enterprise_send_msg.go +++ b/business/jxutils/enterprise_msg/enterprise_send_msg.go @@ -2,6 +2,7 @@ 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" ) @@ -36,6 +37,7 @@ 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 { @@ -65,5 +67,6 @@ func SendEnterpriseUserMessage(msgType, phone, title, content string) (err error DuplicateCheckInterval: 0, }) } + globals.SugarLogger.Errorf("SendEnterpriseUserMessage err2 %v", err) return err } diff --git a/business/jxutils/tasksch/task.go b/business/jxutils/tasksch/task.go index f8edc2c5b..f03d8fcd3 100644 --- a/business/jxutils/tasksch/task.go +++ b/business/jxutils/tasksch/task.go @@ -510,7 +510,9 @@ func SendMessage(t *BaseTask) { content += ",\n" + t.Error() } if err := ddmsg.SendUserMessage(dingdingapi.MsgTyeText, authInfo.UserID, "异步任务完成", content); err != nil { - enterprise_msg.SendUserMessage(authInfo.Mobile, "异步任务完成", "", content) + globals.SugarLogger.Errorf("==============errr ddd %v", err) + err2 := enterprise_msg.SendUserMessage(authInfo.Mobile, "异步任务完成", "", content) + globals.SugarLogger.Errorf("==============errr ddd %v", err2) } } } From 10bfe1a6e11ef2ed7caa6b2a63979158241b9dd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Sun, 29 Jan 2023 15:55:04 +0800 Subject: [PATCH 04/17] 1 --- business/jxutils/ddmsg/ddmsg.go | 1 + business/jxutils/tasksch/task.go | 1 + 2 files changed, 2 insertions(+) diff --git a/business/jxutils/ddmsg/ddmsg.go b/business/jxutils/ddmsg/ddmsg.go index a4d60e0d5..3498140e9 100644 --- a/business/jxutils/ddmsg/ddmsg.go +++ b/business/jxutils/ddmsg/ddmsg.go @@ -21,6 +21,7 @@ func SendDDUserMessage(msgType, ddUserID, title, content string) (err error) { err = api.DingDingAPI.CorpAsyncSendMarkdown([]string{ddUserID}, nil, false, title, content) } } + globals.SugarLogger.Errorf("========SendDDUserMessage err=============== %v,%s", err, ddUserID) return err } diff --git a/business/jxutils/tasksch/task.go b/business/jxutils/tasksch/task.go index f03d8fcd3..98b9dd598 100644 --- a/business/jxutils/tasksch/task.go +++ b/business/jxutils/tasksch/task.go @@ -509,6 +509,7 @@ func SendMessage(t *BaseTask) { } else { content += ",\n" + t.Error() } + 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) From d1871e65414e96cb792645e1e5458088ec6866cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Sun, 29 Jan 2023 16:12:49 +0800 Subject: [PATCH 05/17] 1 --- business/jxutils/ddmsg/ddmsg.go | 5 ++++- business/jxutils/enterprise_msg/enterprise_send_msg.go | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/business/jxutils/ddmsg/ddmsg.go b/business/jxutils/ddmsg/ddmsg.go index 3498140e9..c5a7b6c12 100644 --- a/business/jxutils/ddmsg/ddmsg.go +++ b/business/jxutils/ddmsg/ddmsg.go @@ -2,6 +2,7 @@ package ddmsg import ( "fmt" + "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/business/jxutils/enterprise_msg" "git.rosy.net.cn/jx-callback/business/model/dao" @@ -41,7 +42,9 @@ func SendUserMessage(msgType, userID, title, content string) (err error) { globals.SugarLogger.Errorf("get user err %v", err) continue } - enterprise_msg.SendUserMessage(*userInfo.Mobile, title, "", content) + globals.SugarLogger.Debugf("=============userInfo %s", utils.Format4Output(userInfo, false)) + err3 := enterprise_msg.SendUserMessage(*userInfo.Mobile, title, "", content) + globals.SugarLogger.Errorf("=======err3 %v", err3) } break } diff --git a/business/jxutils/enterprise_msg/enterprise_send_msg.go b/business/jxutils/enterprise_msg/enterprise_send_msg.go index 629f08a76..ef54ba2fa 100644 --- a/business/jxutils/enterprise_msg/enterprise_send_msg.go +++ b/business/jxutils/enterprise_msg/enterprise_send_msg.go @@ -8,6 +8,7 @@ import ( // SendUserMessage 发送文本卡片 func SendUserMessage(phone, title, description, url string) error { + globals.SugarLogger.Debugf("=========================进来了") // 根据电话号码获取用户touserId enterpriseUserId, err := api.EnterpriseChatMin.GetUserIdByMobile(phone) if err != nil { From 6bcdb4c59a0c4133e049a26ff66b7205ad66d74a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Sun, 29 Jan 2023 16:17:38 +0800 Subject: [PATCH 06/17] =?UTF-8?q?=E6=96=AD=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxutils/ddmsg/ddmsg.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/business/jxutils/ddmsg/ddmsg.go b/business/jxutils/ddmsg/ddmsg.go index c5a7b6c12..8e35adaec 100644 --- a/business/jxutils/ddmsg/ddmsg.go +++ b/business/jxutils/ddmsg/ddmsg.go @@ -43,7 +43,8 @@ func SendUserMessage(msgType, userID, title, content string) (err error) { continue } globals.SugarLogger.Debugf("=============userInfo %s", utils.Format4Output(userInfo, false)) - err3 := enterprise_msg.SendUserMessage(*userInfo.Mobile, title, "", content) + globals.SugarLogger.Debugf("=============content %s", utils.Format4Output(content, false)) + err3 := enterprise_msg.SendUserMessage(*userInfo.Mobile, title, content, content) globals.SugarLogger.Errorf("=======err3 %v", err3) } break From 2956279f75b6a3a7b78fd572d76ed5d0e5b4d4fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Sun, 29 Jan 2023 16:21:56 +0800 Subject: [PATCH 07/17] 1 --- business/jxutils/ddmsg/ddmsg.go | 6 +--- .../enterprise_msg/enterprise_send_msg.go | 35 +++++++++++++------ 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/business/jxutils/ddmsg/ddmsg.go b/business/jxutils/ddmsg/ddmsg.go index 8e35adaec..88929dbb6 100644 --- a/business/jxutils/ddmsg/ddmsg.go +++ b/business/jxutils/ddmsg/ddmsg.go @@ -2,7 +2,6 @@ package ddmsg import ( "fmt" - "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/business/jxutils/enterprise_msg" "git.rosy.net.cn/jx-callback/business/model/dao" @@ -42,10 +41,7 @@ func SendUserMessage(msgType, userID, title, content string) (err error) { globals.SugarLogger.Errorf("get user err %v", err) continue } - globals.SugarLogger.Debugf("=============userInfo %s", utils.Format4Output(userInfo, false)) - globals.SugarLogger.Debugf("=============content %s", utils.Format4Output(content, false)) - err3 := enterprise_msg.SendUserMessage(*userInfo.Mobile, title, content, content) - globals.SugarLogger.Errorf("=======err3 %v", err3) + enterprise_msg.SendUserMessage(*userInfo.Mobile, title, content, content) } break } diff --git a/business/jxutils/enterprise_msg/enterprise_send_msg.go b/business/jxutils/enterprise_msg/enterprise_send_msg.go index ef54ba2fa..f3f27a63c 100644 --- a/business/jxutils/enterprise_msg/enterprise_send_msg.go +++ b/business/jxutils/enterprise_msg/enterprise_send_msg.go @@ -8,25 +8,38 @@ import ( // SendUserMessage 发送文本卡片 func SendUserMessage(phone, title, description, url string) error { - globals.SugarLogger.Debugf("=========================进来了") // 根据电话号码获取用户touserId enterpriseUserId, err := api.EnterpriseChatMin.GetUserIdByMobile(phone) if err != nil { return err } - msg := &enterprise.EnterpriseSendMsgReq{ + err = api.EnterpriseChatMin.SendMsgToUserTypeText(&enterprise.SendTextMsgReq{ Touser: enterpriseUserId, - Msgtype: enterprise.MsgTypeTextCard, + Msgtype: enterprise.MsgTypeText, Agentid: enterprise.EnterpriseAgentid, - Textcard: enterprise.TextCardObject{ - Title: title, - Description: description, - Url: url, - Btntxt: "详情", - }, - } - return api.EnterpriseChatMin.SendMsgToUser(msg) + 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 发送文本消息 From 0c0e640df2f05ebaf21fd7b5d79829b3bc777281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Sun, 29 Jan 2023 16:48:02 +0800 Subject: [PATCH 08/17] =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E8=AF=AD=E5=8F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxutils/ddmsg/ddmsg.go | 1 - 1 file changed, 1 deletion(-) diff --git a/business/jxutils/ddmsg/ddmsg.go b/business/jxutils/ddmsg/ddmsg.go index 88929dbb6..9e89ab195 100644 --- a/business/jxutils/ddmsg/ddmsg.go +++ b/business/jxutils/ddmsg/ddmsg.go @@ -21,7 +21,6 @@ func SendDDUserMessage(msgType, ddUserID, title, content string) (err error) { err = api.DingDingAPI.CorpAsyncSendMarkdown([]string{ddUserID}, nil, false, title, content) } } - globals.SugarLogger.Errorf("========SendDDUserMessage err=============== %v,%s", err, ddUserID) return err } 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 09/17] 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" From de216d9519c77f10bffe1d95ff5f9a1ba6c4c2a9 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 14:46:41 +0800 Subject: [PATCH 10/17] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BF=AB=E6=89=8B?= =?UTF-8?q?=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../authprovider/kuaishou/kuaishou_mini.go | 81 +++++++++---------- conf/app.conf | 18 +++++ globals/api/api.go | 3 + 3 files changed, 57 insertions(+), 45 deletions(-) diff --git a/business/auth2/authprovider/kuaishou/kuaishou_mini.go b/business/auth2/authprovider/kuaishou/kuaishou_mini.go index af2b9d672..189a45250 100644 --- a/business/auth2/authprovider/kuaishou/kuaishou_mini.go +++ b/business/auth2/authprovider/kuaishou/kuaishou_mini.go @@ -1,50 +1,41 @@ 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 -//} -// -//// 特殊接口 +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) diff --git a/conf/app.conf b/conf/app.conf index 578a5cb17..530456f22 100644 --- a/conf/app.conf +++ b/conf/app.conf @@ -200,6 +200,10 @@ fnCode = "uDEyAmTbrfS2qjYbgi20Jm" fnMerchantId= "51658" fnCallbackURL = "http://callback.jxc4.com/fn/msg" +# 快手授权地址 +kuaiShouAppId = "ks680887971696897880" +kuaiShouAppSecret = "1wShCPqUzhg8W1vcb8OdvA" + #uu跑腿 uuAppID="55c4542ae60e4d348edcfc93b06dd302" uuAppKey="76b362c06b1b4baa9e47bab6387a5356" @@ -343,6 +347,10 @@ fnCode = "uDEyAmTbrfS2qjYbgi20Jm" fnMerchantId= "51658" fnCallbackURL = "http://callback.jxc4.com/fn/msg" +# 快手授权地址 +kuaiShouAppId = "ks680887971696897880" +kuaiShouAppSecret = "1wShCPqUzhg8W1vcb8OdvA" + #uu跑腿 uuAppID="55c4542ae60e4d348edcfc93b06dd302" uuAppKey="76b362c06b1b4baa9e47bab6387a5356" @@ -456,6 +464,11 @@ fnAppSecret = "a8248088-a742-4c33-a0db-03aeae00ca7d" fnMerchantId = "51658" fnCode = "uDEyAmTbrfS2qjYbgi20Jm" fnCallbackURL = "http://callback-jxgy.jxc4.com/fn/msg" + +# 快手授权地址 +kuaiShouAppId = "ks680887971696897880" +kuaiShouAppSecret = "1wShCPqUzhg8W1vcb8OdvA" + #uu跑腿 uuAppID="55c4542ae60e4d348edcfc93b06dd302" uuAppKey="76b362c06b1b4baa9e47bab6387a5356" @@ -654,6 +667,11 @@ fnAppSecret = "c1e6c280-e618-4103-9d0a-673bc54fb22e" fnCode = "uDEyAmTbrfS2qjYbgi20Jm" fnMerchantId= "51658" fnCallbackURL = "http://callback.jxc4.com/fn/msg" + +# 快手授权地址 +kuaiShouAppId = "ks680887971696897880" +kuaiShouAppSecret = "1wShCPqUzhg8W1vcb8OdvA" + #uu跑腿 uuAppID="55c4542ae60e4d348edcfc93b06dd302" uuAppKey="76b362c06b1b4baa9e47bab6387a5356" diff --git a/globals/api/api.go b/globals/api/api.go index 26966e111..ea28b8973 100644 --- a/globals/api/api.go +++ b/globals/api/api.go @@ -4,6 +4,7 @@ import ( "git.rosy.net.cn/baseapi/platformapi/ali_logistics_query" enterprise "git.rosy.net.cn/baseapi/platformapi/enterprise_wechat" "git.rosy.net.cn/baseapi/platformapi/jxprintapi" + "git.rosy.net.cn/baseapi/platformapi/kuaishou_mini" "git.rosy.net.cn/baseapi/platformapi/qywxapi" "git.rosy.net.cn/baseapi/platformapi/tiktok" tiktokShop "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/tiktok_api" @@ -125,6 +126,7 @@ var ( EnterpriseChatMin *enterprise.API // 企业微信小程序api LogisticsApi *ali_logistics_query.API // 阿里云提供获取物流订单的配送信息 + KuaiShouApi *kuaishou_mini.API // 快手平台 ) func init() { @@ -320,4 +322,5 @@ func Init() { TiktokStore = tiktokShop.New(beego.AppConfig.DefaultString("tiktokShopAppId", ""), beego.AppConfig.DefaultString("tiktokShopAppSecret", ""), "") EnterpriseChatHeadApi = enterprise.New("ww9a156bfa070e1857", "0jBdCjSmoFiOoHIXyeCK9VbGQ82fVNJZ8uMl6JNN7X4") // 通讯录 EnterpriseChatMin = enterprise.NewMin("ww9a156bfa070e1857", "JQsEmSTltHhNgdPIT320YJFphiYmRs-YZa-rCBwplss") // 小程序 + KuaiShouApi = kuaishou_mini.New(beego.AppConfig.DefaultString("kuaiShouAppSecret", ""), beego.AppConfig.DefaultString("kuaiShouAppId", "")) } From e807295a06d419aeffb851793724b6a0f15aa796 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 14:54:58 +0800 Subject: [PATCH 11/17] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BF=AB=E6=89=8B?= =?UTF-8?q?=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxutils/enterprise_msg/enterprise_send_msg.go | 1 + 1 file changed, 1 insertion(+) diff --git a/business/jxutils/enterprise_msg/enterprise_send_msg.go b/business/jxutils/enterprise_msg/enterprise_send_msg.go index a78ae4e1e..49854bc01 100644 --- a/business/jxutils/enterprise_msg/enterprise_send_msg.go +++ b/business/jxutils/enterprise_msg/enterprise_send_msg.go @@ -20,6 +20,7 @@ var enterpriseUserIdMap = map[string]string{ "18780171617": "TianQinXin", "17381914617": "TianQinXin2", "18583684218": "JingXiCaiShi-YanXiaoKang18583684218", + "17381580510": "YouRan", } // SendUserMessage 发送文本卡片 From 19e05d098cee85b7ab1d0233e8091f5a7f545e02 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 15:18:05 +0800 Subject: [PATCH 12/17] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BF=AB=E6=89=8B?= =?UTF-8?q?=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 6f3c4263d..584359015 100644 --- a/main.go +++ b/main.go @@ -41,6 +41,10 @@ import ( _ "git.rosy.net.cn/jx-callback/business/auth2/authprovider/alipay" _ "git.rosy.net.cn/jx-callback/business/auth2/authprovider/dingding" _ "git.rosy.net.cn/jx-callback/business/auth2/authprovider/douyin" + _ "git.rosy.net.cn/jx-callback/business/auth2/authprovider/kuaishou" + _ "git.rosy.net.cn/jx-callback/business/auth2/authprovider/mobile" + _ "git.rosy.net.cn/jx-callback/business/auth2/authprovider/password" + _ "git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin" _ "git.rosy.net.cn/jx-callback/business/enterprise" _ "git.rosy.net.cn/jx-callback/business/model/dao" _ "git.rosy.net.cn/jx-callback/business/partner/purchase/ebai" @@ -48,10 +52,6 @@ import ( _ "git.rosy.net.cn/jx-callback/business/partner/purchase/jx" _ "git.rosy.net.cn/jx-callback/business/partner/purchase/mtwm" _ "git.rosy.net.cn/jx-callback/business/partner/purchase/weimob/wsc" - //_ "git.rosy.net.cn/jx-callback/business/auth2/authprovider/douyin" - _ "git.rosy.net.cn/jx-callback/business/auth2/authprovider/mobile" - _ "git.rosy.net.cn/jx-callback/business/auth2/authprovider/password" - _ "git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin" _ "git.rosy.net.cn/jx-callback/business/jxstore/act" From 63687148fbf309e3d5261a1188d9eb8fe7234763 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 15:42:56 +0800 Subject: [PATCH 13/17] 1 --- business/auth2/auth2.go | 29 +++++++++++++++++++++++------ controllers/auth2.go | 3 ++- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/business/auth2/auth2.go b/business/auth2/auth2.go index 05e8603e2..17acd991e 100644 --- a/business/auth2/auth2.go +++ b/business/auth2/auth2.go @@ -335,7 +335,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 +346,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 +370,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绑定新创建的用户 diff --git a/controllers/auth2.go b/controllers/auth2.go index 47df0f47b..fe5e489be 100644 --- a/controllers/auth2.go +++ b/controllers/auth2.go @@ -92,12 +92,13 @@ func (c *Auth2Controller) SendVerifyCode() { // @Param iv formData string true "加密字符偏移量" // @Param sessionKey formData string true "加密key" // @Param msg formData string true "加密消息" +// @Param loginType formData string true "登录类型兼容抖音登录/快手[tiktokmini/kuaishoumini]" // @Success 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult // @router /TiktokDecrypt [post] func (c *Auth2Controller) TiktokDecrypt() { c.callTiktokDecrypt(func(params *tAuth2TiktokDecryptParams) (interface{}, string, error) { - phone, err := auth2.DecryptUserMsg(params.SessionKey, params.Iv, params.Msg) + phone, err := auth2.DecryptUserMsg(params.SessionKey, params.Iv, params.Msg, params.LoginType) return phone, "", err }) } From c3c7c7ddbde6888401a7c625e73b234b224f1798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Tue, 31 Jan 2023 09:16:28 +0800 Subject: [PATCH 14/17] 1 --- business/auth2/authprovider/weixin/weixin.go | 9 +++++++-- controllers/auth2.go | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/business/auth2/authprovider/weixin/weixin.go b/business/auth2/authprovider/weixin/weixin.go index 443e8d09e..78dd31315 100644 --- a/business/auth2/authprovider/weixin/weixin.go +++ b/business/auth2/authprovider/weixin/weixin.go @@ -2,6 +2,8 @@ package weixin import ( "errors" + "git.rosy.net.cn/baseapi/utils" + "git.rosy.net.cn/jx-callback/globals" "git.rosy.net.cn/baseapi/platformapi/weixinapi" "git.rosy.net.cn/jx-callback/business/auth2" @@ -14,7 +16,7 @@ const ( AuthTypeWeixin = "wxqrcode" // 微信扫码 AuthTypeMP = "weixinsns" // 公众号 AuthTypeWXNative = "wxnative" // 微信APP - AuthTypeWxApp = "weixinapp" //app微信登录 + AuthTypeWxApp = "weixinapp" //app微信登录() ) type Auther struct { @@ -57,7 +59,10 @@ func init() { func (a *Auther) VerifySecret(id, secret string) (authBindEx *auth2.AuthBindEx, err error) { var openID, accessToken string - _, jsCode := SplitJsCode(secret) + appId, jsCode := SplitJsCode(secret) + globals.SugarLogger.Debugf("=======appId := %s ,jscode := %s", appId, jsCode) + globals.SugarLogger.Debugf("auther := %s", utils.Format4Output(a.authType, false)) + globals.SugarLogger.Debugf("auther := %s", utils.Format4Output(a.DefAuther, false)) if a.authType != AuthTypeWXNative { state := id code := jsCode diff --git a/controllers/auth2.go b/controllers/auth2.go index fe5e489be..73ec0e679 100644 --- a/controllers/auth2.go +++ b/controllers/auth2.go @@ -3,6 +3,7 @@ package controllers import ( "encoding/base64" "fmt" + "git.rosy.net.cn/jx-callback/globals" "net/http" "strings" @@ -131,6 +132,7 @@ func (c *Auth2Controller) Login() { params.AuthSecret = GetComposedCode2(&c.Controller, params.AuthSecret) } ctx := auth2.NewContext(c.Ctx.ResponseWriter, c.Ctx.Request) + globals.SugarLogger.Debugf("======参数login === %s", utils.Format4Output(params, false)) authInfo, err := auth2.Login(ctx, params.AuthType, params.AuthID, params.AuthIDType, params.AuthSecret) // TODO 兼容没有取到authid2的错误 if err == nil && authInfo.AuthBindInfo != nil { From 0f45dee310f4080247b62b87357b7c5cc585fe6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Tue, 31 Jan 2023 10:27:15 +0800 Subject: [PATCH 15/17] 1 --- business/auth2/auth2.go | 15 ++++---- business/auth2/authprovider/weixin/weixin.go | 36 +++++++++++--------- business/jxstore/cms/store.go | 6 ++-- business/jxstore/cms/store_sku.go | 4 +-- business/jxstore/cms/user2.go | 2 +- controllers/auth2.go | 6 +++- controllers/cms_user2.go | 2 +- globals/api/api.go | 5 ++- 8 files changed, 44 insertions(+), 32 deletions(-) diff --git a/business/auth2/auth2.go b/business/auth2/auth2.go index 17acd991e..64d843b4b 100644 --- a/business/auth2/auth2.go +++ b/business/auth2/auth2.go @@ -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}) diff --git a/business/auth2/authprovider/weixin/weixin.go b/business/auth2/authprovider/weixin/weixin.go index 78dd31315..d554b8726 100644 --- a/business/auth2/authprovider/weixin/weixin.go +++ b/business/auth2/authprovider/weixin/weixin.go @@ -2,9 +2,6 @@ package weixin import ( "errors" - "git.rosy.net.cn/baseapi/utils" - "git.rosy.net.cn/jx-callback/globals" - "git.rosy.net.cn/baseapi/platformapi/weixinapi" "git.rosy.net.cn/jx-callback/business/auth2" "git.rosy.net.cn/jx-callback/business/auth2/authprovider" @@ -13,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 { @@ -25,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 ( @@ -55,14 +54,16 @@ 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) { var openID, accessToken string - appId, jsCode := SplitJsCode(secret) - globals.SugarLogger.Debugf("=======appId := %s ,jscode := %s", appId, jsCode) - globals.SugarLogger.Debugf("auther := %s", utils.Format4Output(a.authType, false)) - globals.SugarLogger.Debugf("auther := %s", utils.Format4Output(a.DefAuther, false)) + _, jsCode := SplitJsCode(secret) if a.authType != AuthTypeWXNative { state := id code := jsCode @@ -94,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, @@ -112,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 } diff --git a/business/jxstore/cms/store.go b/business/jxstore/cms/store.go index 9788a251e..6764338eb 100644 --- a/business/jxstore/cms/store.go +++ b/business/jxstore/cms/store.go @@ -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 diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index 4578864cc..4399c586f 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -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 { diff --git a/business/jxstore/cms/user2.go b/business/jxstore/cms/user2.go index acee612d3..b5d8e3a65 100644 --- a/business/jxstore/cms/user2.go +++ b/business/jxstore/cms/user2.go @@ -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!") diff --git a/controllers/auth2.go b/controllers/auth2.go index 73ec0e679..c54414408 100644 --- a/controllers/auth2.go +++ b/controllers/auth2.go @@ -38,12 +38,16 @@ func GetComposedCode2(c *web.Controller, code string) (composedCode string) { composedCode = code referer := c.Ctx.Request.UserAgent() index := strings.Index(referer, "//") + globals.SugarLogger.Debugf("====GetComposedCode2==== %s", referer) if index > 0 { list := strings.Split(referer[index+2:], "/") + globals.SugarLogger.Debugf("====GetComposedCode2===list= %s", utils.Format4Output(list, false)) if len(list) >= 2 { composedCode = weixin.ComposeJsCode(list[1], code) } } + globals.SugarLogger.Debugf("====composedCode===list= %s", utils.Format4Output(composedCode, false)) + return composedCode } @@ -123,7 +127,7 @@ func (c *Auth2Controller) Login() { if params.AuthType == weixin.AuthTypeMini { params.AuthSecret = GetComposedCode(&c.Controller, params.AuthSecret) } - if params.AuthType == weixin.AuthTypeWxApp { + if params.AuthType == weixin.AuthTypeWxApp || params.AuthType == weixin.AuthTypeWxAppCaishi { //if configs, _ := dao.QueryConfigs(dao.GetDB(), "checkversion", model.ConfigTypeSys, ""); len(configs) > 0 { // if params.Version == "" || configs[0].Value != params.Version { // return nil, "", fmt.Errorf("当前APP版本过旧,数据显示有错误,请到'京西菜市'公众号下载最新版本APP!") diff --git a/controllers/cms_user2.go b/controllers/cms_user2.go index 8a098626b..3307a4d95 100644 --- a/controllers/cms_user2.go +++ b/controllers/cms_user2.go @@ -39,7 +39,7 @@ func (c *User2Controller) RegisterUser() { ) if params.AuthToken != "" { inAuthInfo, err = auth2.GetTokenInfo(params.AuthToken) - if inAuthInfo.AuthBindInfo.Type == weixin.AuthTypeWxApp { + if inAuthInfo.AuthBindInfo.Type == weixin.AuthTypeWxApp || inAuthInfo.AuthBindInfo.Type == weixin.AuthTypeWxAppCaishi { if configs, _ := dao.QueryConfigs(dao.GetDB(), "checkversion", model.ConfigTypeSys, ""); len(configs) > 0 { if params.Version == "" || configs[0].Value != params.Version { return nil, "", fmt.Errorf("当前APP版本过旧,数据显示有错误,请到'京西菜市'公众号下载最新版本APP!") diff --git a/globals/api/api.go b/globals/api/api.go index ea28b8973..b3e529867 100644 --- a/globals/api/api.go +++ b/globals/api/api.go @@ -80,7 +80,8 @@ var ( WeixinMiniAPI2 *weixinapi.API // 小程序2 WeixinMiniAPIsc *weixinapi.API //小程序商超 WeixinMiniAPIPrint *weixinapi.API //小程序打印机 - WeixinApp *weixinapi.API // app微信登录 + WeixinApp *weixinapi.API // app微信登录(商家端App微信授权) + WeixinApp2 *weixinapi.API // app微信登录(菜市端App微信授权) WeixinMiniAppID2 string WeixinMiniAppID3 string WeixinMiniAppIDsc string @@ -267,6 +268,8 @@ func Init() { if WeixinMiniAppID3 = beego.AppConfig.DefaultString("weixinMiniAppID3", ""); WeixinMiniAppID3 != "" { WeixinApp = weixinapi.New(WeixinMiniAppID3, beego.AppConfig.DefaultString("weixinMiniSecret3", "")) } + WeixinApp2 = weixinapi.New("wxf3657c94aa01a3f0", "358b794343bfb48a32ccbf1d9052a30") // 暂时写死的 + if WeixinMiniAppIDsc = beego.AppConfig.DefaultString("weixinMiniAppIDsc", ""); WeixinMiniAppIDsc != "" { WeixinMiniAPIsc = weixinapi.New(WeixinMiniAppIDsc, beego.AppConfig.DefaultString("weixinMiniSecretsc", "")) } From b63f39aae1c2868990724dde201659206532c9e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Tue, 31 Jan 2023 10:45:06 +0800 Subject: [PATCH 16/17] 1 --- controllers/auth2.go | 4 ---- globals/api/api.go | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/controllers/auth2.go b/controllers/auth2.go index c54414408..a2e5801cf 100644 --- a/controllers/auth2.go +++ b/controllers/auth2.go @@ -38,16 +38,12 @@ func GetComposedCode2(c *web.Controller, code string) (composedCode string) { composedCode = code referer := c.Ctx.Request.UserAgent() index := strings.Index(referer, "//") - globals.SugarLogger.Debugf("====GetComposedCode2==== %s", referer) if index > 0 { list := strings.Split(referer[index+2:], "/") - globals.SugarLogger.Debugf("====GetComposedCode2===list= %s", utils.Format4Output(list, false)) if len(list) >= 2 { composedCode = weixin.ComposeJsCode(list[1], code) } } - globals.SugarLogger.Debugf("====composedCode===list= %s", utils.Format4Output(composedCode, false)) - return composedCode } diff --git a/globals/api/api.go b/globals/api/api.go index b3e529867..a79bcd1e2 100644 --- a/globals/api/api.go +++ b/globals/api/api.go @@ -268,7 +268,7 @@ func Init() { if WeixinMiniAppID3 = beego.AppConfig.DefaultString("weixinMiniAppID3", ""); WeixinMiniAppID3 != "" { WeixinApp = weixinapi.New(WeixinMiniAppID3, beego.AppConfig.DefaultString("weixinMiniSecret3", "")) } - WeixinApp2 = weixinapi.New("wxf3657c94aa01a3f0", "358b794343bfb48a32ccbf1d9052a30") // 暂时写死的 + WeixinApp2 = weixinapi.New("wxf3657c94aa01a3f0", "ce2b9c4cf991d72a09f67bab4d359015") // 暂时写死的 if WeixinMiniAppIDsc = beego.AppConfig.DefaultString("weixinMiniAppIDsc", ""); WeixinMiniAppIDsc != "" { WeixinMiniAPIsc = weixinapi.New(WeixinMiniAppIDsc, beego.AppConfig.DefaultString("weixinMiniSecretsc", "")) From 128117ca6d2cb3de4200c0e064f65f3c09a57022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Tue, 31 Jan 2023 10:51:50 +0800 Subject: [PATCH 17/17] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/auth2.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/controllers/auth2.go b/controllers/auth2.go index a2e5801cf..e42a98b55 100644 --- a/controllers/auth2.go +++ b/controllers/auth2.go @@ -3,7 +3,6 @@ package controllers import ( "encoding/base64" "fmt" - "git.rosy.net.cn/jx-callback/globals" "net/http" "strings" @@ -132,7 +131,6 @@ func (c *Auth2Controller) Login() { params.AuthSecret = GetComposedCode2(&c.Controller, params.AuthSecret) } ctx := auth2.NewContext(c.Ctx.ResponseWriter, c.Ctx.Request) - globals.SugarLogger.Debugf("======参数login === %s", utils.Format4Output(params, false)) authInfo, err := auth2.Login(ctx, params.AuthType, params.AuthID, params.AuthIDType, params.AuthSecret) // TODO 兼容没有取到authid2的错误 if err == nil && authInfo.AuthBindInfo != nil {