+ EnableWXAuth2

This commit is contained in:
gazebo
2019-08-12 17:54:00 +08:00
parent c5a5f4777b
commit 339b60c374
6 changed files with 119 additions and 40 deletions

View File

@@ -244,7 +244,7 @@ func GetStores(ctx *jxcontext.Context, keyword string, params map[string]interfa
sqlWhereParams = append(sqlWhereParams, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike)
if keywordInt64, err2 := strconv.ParseInt(keyword, 10, 64); err2 == nil {
if jxutils.IsLegalMobileNumber(keywordInt64) {
if !globals.EnableWXAuth2 && jxutils.IsLegalMobileNumber(keywordInt64) {
sql += `
LEFT JOIN weixins wx1 ON t1.id = wx1.jxstoreid AND wx1.parentid = -1 AND wx1.tel = ?
LEFT JOIN weixins wx2 ON t1.id = wx2.jxstoreid AND wx2.parentid = -1

View File

@@ -8,6 +8,7 @@ import (
"sync"
"time"
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
"git.rosy.net.cn/jx-callback/business/partner/delivery"
"git.rosy.net.cn/baseapi/platformapi/jdapi"
@@ -899,18 +900,32 @@ func PrintMsg(ctx *jxcontext.Context, vendorID int, id1, id2, msgTitle, msgConte
}
func UpdateAllWeiXinRemark(ctx *jxcontext.Context, isAsync, isContinueWhenError bool) (hint string, err error) {
var weixinList []*legacymodel.WeiXins
if err = dao.GetRows(dao.GetDB(), &weixinList, `
SELECT *
var mobileList []string
sql := `
SELECT tel
FROM weixins
WHERE openid <> '' AND tel <> ''
`); err == nil {
WHERE openid <> '' AND tel <> ''`
sqlParams := []interface{}{}
if globals.EnableWXAuth2 {
sql = `
SELECT t1.mobile
FROM user t1
JOIN auth_bind t2 ON t2.user_id = t1.user_id AND t2.deleted_at = ? and t2.type = ?
WHERE t1.deleted_at = ? AND t1.type & ? <> 0`
sqlParams = []interface{}{
utils.DefaultTimeValue,
weixin.AuthTypeMP,
utils.DefaultTimeValue,
model.UserTypeStoreBoss,
}
}
if err = dao.GetRows(dao.GetDB(), &mobileList, sql, sqlParams...); err == nil {
rootTask := tasksch.NewParallelTask("刷新微信备注", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
weixins := batchItemList[0].(*legacymodel.WeiXins)
err = jxutils.HandleUserWXRemark(dao.GetDB(), weixins.Tel)
tel := batchItemList[0].(string)
err = jxutils.HandleUserWXRemark(dao.GetDB(), tel)
return nil, err
}, weixinList)
}, mobileList)
tasksch.ManageTask(rootTask).Run()
if !isAsync {
_, err = rootTask.GetResult(0)

View File

@@ -4,21 +4,23 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"math"
"math/rand"
"regexp"
"sort"
"strings"
"time"
"io/ioutil"
"git.rosy.net.cn/baseapi/platformapi/autonavi"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/baseapi/utils/routinepool"
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
"git.rosy.net.cn/jx-callback/globals/api2"
"github.com/qiniu/api.v7/storage"
)
@@ -425,13 +427,36 @@ func HandleUserWXRemark(db *dao.DaoDB, mobile string) (err error) {
if db == nil {
db = dao.GetDB()
}
wxinfo, err := dao.GetUserStoreInfo(db, "tel", mobile)
openID := ""
storeID := 0
remark := ""
if !globals.EnableWXAuth2 {
wxinfo, err := dao.GetUserStoreInfo(db, "tel", mobile)
if err == nil {
openID = wxinfo.OpenID
storeID = wxinfo.JxStoreID
}
} else {
userList, err2 := dao.GetUsers(db, model.UserTypeStoreBoss, "", nil, "", mobile)
if err = err2; len(userList) > 0 {
userID := userList[0].GetID()
authBind, err2 := dao.GetAuthBind(db, userID, weixin.AuthTypeMP, "")
if err = err2; err == nil {
openID = authBind.AuthID
}
roleList, err2 := api2.RoleMan.GetUserRoleList(userID)
if err = err2; err == nil && len(roleList) > 0 {
storeID = roleList[0].StoreID
}
}
}
if err == nil {
if wxinfo.OpenID != "" {
remark := ""
if wxinfo.JxStoreID > 0 {
if openID != "" {
if storeID > 0 {
store := &model.Store{}
store.ID = wxinfo.JxStoreID
store.ID = storeID
if err = dao.GetEntity(db, store); err == nil {
city := &model.Place{
Code: store.CityCode,
@@ -442,7 +467,7 @@ func HandleUserWXRemark(db *dao.DaoDB, mobile string) (err error) {
}
}
if err == nil {
err = api.WeixinAPI.CBUpdateRemark(wxinfo.OpenID, remark)
err = api.WeixinAPI.CBUpdateRemark(openID, remark)
}
}
}
@@ -624,4 +649,4 @@ func GetEbaiOrderGetCode(order *model.GoodsOrder) (getCode string) {
func WriteFile(fileName string, binData []byte) error {
err := ioutil.WriteFile(fileName, binData, 0666)
return err
}
}

View File

@@ -5,6 +5,9 @@ import (
"strings"
"time"
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
"git.rosy.net.cn/jx-callback/business/authz"
"git.rosy.net.cn/jx-callback/business/authz/autils"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
"git.rosy.net.cn/jx-callback/business/jxutils/netprinter"
@@ -13,10 +16,11 @@ import (
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/jx-callback/business/model/legacymodel"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
"github.com/astaxie/beego/orm"
"git.rosy.net.cn/jx-callback/globals/api2"
)
const (
@@ -82,27 +86,41 @@ var (
)
func GetWeixinOpenIDsFromStoreID(storeID int) (retVal []string) {
db := orm.NewOrm()
var lists []orm.ParamsList
num, err := db.Raw(`
SELECT openid
FROM weixins t1
JOIN
(SELECT id
FROM weixins
WHERE jxstoreid = ? AND parentid = -1) t2 ON t2.id = t1.parentid
WHERE openid IS NOT NULL
UNION
SELECT openid
FROM weixins
WHERE jxstoreid = ? AND parentid = -1 AND openid IS NOT NULL
`, storeID, storeID).ValuesList(&lists)
if err != nil || num == 0 {
globals.SugarLogger.Infof("GetWeixinOpenIDsFromStoreID can not find openid for store:%d, num:%d, error:%v", storeID, num, err)
return retVal
}
for _, v := range lists {
retVal = append(retVal, v[0].(string))
db := dao.GetDB()
if !globals.EnableWXAuth2 {
var openIDList []string
sql := `
SELECT openid
FROM weixins t1
JOIN
(SELECT id
FROM weixins
WHERE jxstoreid = ? AND parentid = -1) t2 ON t2.id = t1.parentid
WHERE openid IS NOT NULL
UNION
SELECT openid
FROM weixins
WHERE jxstoreid = ? AND parentid = -1 AND openid IS NOT NULL`
sqlParams := []interface{}{
storeID,
storeID,
}
err := dao.GetRows(db, &openIDList, sql, sqlParams...)
if err != nil || len(openIDList) == 0 {
globals.SugarLogger.Infof("GetWeixinOpenIDsFromStoreID can not find openid for store:%d, num:%d, error:%v", storeID, len(openIDList), err)
return retVal
}
for _, v := range openIDList {
retVal = append(retVal, v)
}
} else {
if userIDList, err2 := api2.RoleMan.GetRoleUserList(autils.NewRole(authz.StoreRoleBoss, storeID)); err2 == nil {
for _, v := range userIDList {
if authInfo, err2 := dao.GetAuthBind(db, v, weixin.AuthTypeMP, ""); err2 == nil {
retVal = append(retVal, authInfo.AuthID)
}
}
}
}
if !globals.ReallyCallPlatformAPI {
// todo调试只发给我

View File

@@ -0,0 +1,20 @@
package weixinmsg
import (
"testing"
"git.rosy.net.cn/jx-callback/globals/api2"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/globals/testinit"
)
func init() {
testinit.Init()
api2.Init()
}
func TestGetWeixinOpenIDsFromStoreID(t *testing.T) {
openIDs := GetWeixinOpenIDsFromStoreID(100118)
t.Log(utils.Format4Output(openIDs, false))
}

View File

@@ -44,7 +44,8 @@ var (
StoreName string
EnableNewAct bool
EnableNewAct bool
EnableWXAuth2 bool
)
func init() {