|
@@ -1,166 +1,166 @@
|
|
|
package entity
|
|
|
|
|
|
import (
|
|
|
- fx "app.yhyue.com/moapp/jypkg/filter/xweb"
|
|
|
- "encoding/json"
|
|
|
- "errors"
|
|
|
- "fmt"
|
|
|
- "jy/src/jfw/modules/publicapply/src/config"
|
|
|
- "jy/src/jfw/modules/publicapply/src/db"
|
|
|
- "jy/src/jfw/modules/publicapply/src/jyutil"
|
|
|
- "jy/src/jfw/modules/publicapply/src/oneclick/initjson"
|
|
|
- pu "jy/src/jfw/modules/publicapply/src/util"
|
|
|
- "log"
|
|
|
- "net/http"
|
|
|
- "strings"
|
|
|
- "sync"
|
|
|
- "time"
|
|
|
+ fx "app.yhyue.com/moapp/jypkg/filter/xweb"
|
|
|
+ "encoding/json"
|
|
|
+ "errors"
|
|
|
+ "fmt"
|
|
|
+ "jy/src/jfw/modules/publicapply/src/config"
|
|
|
+ "jy/src/jfw/modules/publicapply/src/db"
|
|
|
+ "jy/src/jfw/modules/publicapply/src/jyutil"
|
|
|
+ "jy/src/jfw/modules/publicapply/src/oneclick/initjson"
|
|
|
+ pu "jy/src/jfw/modules/publicapply/src/util"
|
|
|
+ "log"
|
|
|
+ "net/http"
|
|
|
+ "strings"
|
|
|
+ "sync"
|
|
|
+ "time"
|
|
|
|
|
|
- "github.com/gogf/gf/v2/util/gconv"
|
|
|
+ "github.com/gogf/gf/v2/util/gconv"
|
|
|
|
|
|
- "app.yhyue.com/moapp/jybase/common"
|
|
|
- "app.yhyue.com/moapp/jybase/date"
|
|
|
- "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
- "app.yhyue.com/moapp/jybase/go-xweb/httpsession"
|
|
|
- "app.yhyue.com/moapp/jybase/mongodb"
|
|
|
- "app.yhyue.com/moapp/jybase/redis"
|
|
|
- qrpc "app.yhyue.com/moapp/jybase/rpc"
|
|
|
- "app.yhyue.com/moapp/jybase/usercenter"
|
|
|
- "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
|
|
|
- "app.yhyue.com/moapp/jypkg/public"
|
|
|
- "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
|
|
|
- openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
|
|
- dypnsapi20170525 "github.com/alibabacloud-go/dypnsapi-20170525/v2/client"
|
|
|
- util "github.com/alibabacloud-go/tea-utils/v2/service"
|
|
|
- "github.com/alibabacloud-go/tea/tea"
|
|
|
+ "app.yhyue.com/moapp/jybase/common"
|
|
|
+ "app.yhyue.com/moapp/jybase/date"
|
|
|
+ "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
+ "app.yhyue.com/moapp/jybase/go-xweb/httpsession"
|
|
|
+ "app.yhyue.com/moapp/jybase/mongodb"
|
|
|
+ "app.yhyue.com/moapp/jybase/redis"
|
|
|
+ qrpc "app.yhyue.com/moapp/jybase/rpc"
|
|
|
+ "app.yhyue.com/moapp/jybase/usercenter"
|
|
|
+ "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
|
|
|
+ "app.yhyue.com/moapp/jypkg/public"
|
|
|
+ "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
|
|
|
+ openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
|
|
+ dypnsapi20170525 "github.com/alibabacloud-go/dypnsapi-20170525/v2/client"
|
|
|
+ util "github.com/alibabacloud-go/tea-utils/v2/service"
|
|
|
+ "github.com/alibabacloud-go/tea/tea"
|
|
|
)
|
|
|
|
|
|
type OneClickInfo struct {
|
|
|
- AccessToken string `json:"accessToken"`
|
|
|
- OutId string `json:"outId"`
|
|
|
- SpToken string `json:"spToken"`
|
|
|
- Phone string `json:"phone"`
|
|
|
- ActionType string `json:"actionType"`
|
|
|
- Rid string `json:"rid"`
|
|
|
- Oid string `json:"oid"`
|
|
|
- PhoneType string `json:"phoneType"`
|
|
|
- Channel string `json:"channel"`
|
|
|
- DeviceId string `json:"deviceId"`
|
|
|
- UA string `json:"UA"`
|
|
|
- DisWord string `json:"disWord"`
|
|
|
- RequestId string `json:"requestid"`
|
|
|
- Vender string `json:"vender"`
|
|
|
- Activity string `json:"activity"`
|
|
|
- Session *httpsession.Session
|
|
|
- ResponseWriter *http.ResponseWriter
|
|
|
- Host string
|
|
|
- R *http.Request
|
|
|
+ AccessToken string `json:"accessToken"`
|
|
|
+ OutId string `json:"outId"`
|
|
|
+ SpToken string `json:"spToken"`
|
|
|
+ Phone string `json:"phone"`
|
|
|
+ ActionType string `json:"actionType"`
|
|
|
+ Rid string `json:"rid"`
|
|
|
+ Oid string `json:"oid"`
|
|
|
+ PhoneType string `json:"phoneType"`
|
|
|
+ Channel string `json:"channel"`
|
|
|
+ DeviceId string `json:"deviceId"`
|
|
|
+ UA string `json:"UA"`
|
|
|
+ DisWord string `json:"disWord"`
|
|
|
+ RequestId string `json:"requestid"`
|
|
|
+ Vender string `json:"vender"`
|
|
|
+ Activity string `json:"activity"`
|
|
|
+ Session *httpsession.Session
|
|
|
+ ResponseWriter *http.ResponseWriter
|
|
|
+ Host string
|
|
|
+ R *http.Request
|
|
|
}
|
|
|
|
|
|
var (
|
|
|
- RegLock = sync.Mutex{}
|
|
|
- RegMap = map[string]*RegStruct{}
|
|
|
- kickedTip = "您的账号在其他设备登录,如有需要请重新登录。"
|
|
|
+ RegLock = sync.Mutex{}
|
|
|
+ RegMap = map[string]*RegStruct{}
|
|
|
+ kickedTip = "您的账号在其他设备登录,如有需要请重新登录。"
|
|
|
)
|
|
|
|
|
|
const (
|
|
|
- PhoneHasBind = "手机号已被绑定"
|
|
|
+ PhoneHasBind = "手机号已被绑定"
|
|
|
)
|
|
|
|
|
|
func init() {
|
|
|
- rs := &RegStruct{
|
|
|
- MapR: map[string]int64{},
|
|
|
- Lock: sync.Mutex{},
|
|
|
- }
|
|
|
- go rs.GC()
|
|
|
+ rs := &RegStruct{
|
|
|
+ MapR: map[string]int64{},
|
|
|
+ Lock: sync.Mutex{},
|
|
|
+ }
|
|
|
+ go rs.GC()
|
|
|
}
|
|
|
func (o *OneClickInfo) GetPhoneByToken() (map[string]interface{}, error) {
|
|
|
- err, phone := func() (_err error, phone string) {
|
|
|
- var (
|
|
|
- tryErr error
|
|
|
- client *dypnsapi20170525.Client
|
|
|
- )
|
|
|
- client, _err = CreateClient()
|
|
|
- if _err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- if o.SpToken != "" {
|
|
|
- getPhoneWithTokenRequest := &dypnsapi20170525.GetPhoneWithTokenRequest{
|
|
|
- SpToken: &o.SpToken,
|
|
|
- }
|
|
|
- runtime := &util.RuntimeOptions{}
|
|
|
- tryErr, phone = func() (_e error, p string) {
|
|
|
- defer func() {
|
|
|
- if r := tea.Recover(recover()); r != nil {
|
|
|
- _e = r
|
|
|
- }
|
|
|
- }()
|
|
|
- // 复制代码运行请自行打印 API 的返回值
|
|
|
- _result, _err := client.GetPhoneWithTokenWithOptions(getPhoneWithTokenRequest, runtime)
|
|
|
- log.Println("GetPhoneWithTokenWithOptions _result:", _result)
|
|
|
- if _err != nil {
|
|
|
- log.Println("GetPhoneWithTokenWithOptions:_err", _err)
|
|
|
- if _result.Body != nil {
|
|
|
- log.Println("GetPhoneWithTokenWithOptions _result", _result.Body.Code, _result.Body.Message)
|
|
|
- }
|
|
|
- if strings.Contains(_err.Error(), "GET_MOBILE_FAILED") {
|
|
|
- return fmt.Errorf("输入手机号码和当前流量卡运营商归属不一致"), ""
|
|
|
- }
|
|
|
- return fmt.Errorf("无法识别网络环境,请使用验证码登录"), ""
|
|
|
- }
|
|
|
- if *_result.Body.Code == "OK" {
|
|
|
- //获取手机号
|
|
|
- return nil, *_result.Body.Data.Mobile
|
|
|
- } else {
|
|
|
- log.Println("GetPhoneWithTokenWithOptions:", *_result.Body.Message, *_result.Body.Code, o.SpToken)
|
|
|
- return fmt.Errorf("无法识别网络环境,请使用验证码登录"), ""
|
|
|
- }
|
|
|
+ err, phone := func() (_err error, phone string) {
|
|
|
+ var (
|
|
|
+ tryErr error
|
|
|
+ client *dypnsapi20170525.Client
|
|
|
+ )
|
|
|
+ client, _err = CreateClient()
|
|
|
+ if _err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if o.SpToken != "" {
|
|
|
+ getPhoneWithTokenRequest := &dypnsapi20170525.GetPhoneWithTokenRequest{
|
|
|
+ SpToken: &o.SpToken,
|
|
|
+ }
|
|
|
+ runtime := &util.RuntimeOptions{}
|
|
|
+ tryErr, phone = func() (_e error, p string) {
|
|
|
+ defer func() {
|
|
|
+ if r := tea.Recover(recover()); r != nil {
|
|
|
+ _e = r
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ // 复制代码运行请自行打印 API 的返回值
|
|
|
+ _result, _err := client.GetPhoneWithTokenWithOptions(getPhoneWithTokenRequest, runtime)
|
|
|
+ log.Println("GetPhoneWithTokenWithOptions _result:", _result)
|
|
|
+ if _err != nil {
|
|
|
+ log.Println("GetPhoneWithTokenWithOptions:_err", _err)
|
|
|
+ if _result.Body != nil {
|
|
|
+ log.Println("GetPhoneWithTokenWithOptions _result", _result.Body.Code, _result.Body.Message)
|
|
|
+ }
|
|
|
+ if strings.Contains(_err.Error(), "GET_MOBILE_FAILED") {
|
|
|
+ return fmt.Errorf("输入手机号码和当前流量卡运营商归属不一致"), ""
|
|
|
+ }
|
|
|
+ return fmt.Errorf("无法识别网络环境,请使用验证码登录"), ""
|
|
|
+ }
|
|
|
+ if *_result.Body.Code == "OK" {
|
|
|
+ //获取手机号
|
|
|
+ return nil, *_result.Body.Data.Mobile
|
|
|
+ } else {
|
|
|
+ log.Println("GetPhoneWithTokenWithOptions:", *_result.Body.Message, *_result.Body.Code, o.SpToken)
|
|
|
+ return fmt.Errorf("无法识别网络环境,请使用验证码登录"), ""
|
|
|
+ }
|
|
|
|
|
|
- //return fmt.Errorf(*_result.Body.Message), ""
|
|
|
- }()
|
|
|
- } else if o.AccessToken != "" {
|
|
|
- getMobileRequest := &dypnsapi20170525.GetMobileRequest{
|
|
|
- AccessToken: &o.AccessToken,
|
|
|
- OutId: &o.OutId,
|
|
|
- }
|
|
|
- runtime := &util.RuntimeOptions{}
|
|
|
- tryErr, phone = func() (_e error, p string) {
|
|
|
- defer func() {
|
|
|
- if r := tea.Recover(recover()); r != nil {
|
|
|
- _e = r
|
|
|
- }
|
|
|
- }()
|
|
|
- // 复制代码运行请自行打印 API 的返回值
|
|
|
- _result, _err := client.GetMobileWithOptions(getMobileRequest, runtime)
|
|
|
- if _err != nil {
|
|
|
- return _err, ""
|
|
|
- }
|
|
|
- if *_result.Body.Code == "OK" {
|
|
|
- //获取手机号
|
|
|
- return nil, *_result.Body.GetMobileResultDTO.Mobile
|
|
|
- }
|
|
|
- return fmt.Errorf(*_result.Body.Message), ""
|
|
|
- }()
|
|
|
- }
|
|
|
- if tryErr != nil {
|
|
|
- var sdkError = &tea.SDKError{}
|
|
|
- if _t, ok := tryErr.(*tea.SDKError); ok {
|
|
|
- sdkError = _t
|
|
|
- } else {
|
|
|
- sdkError.Message = tea.String(tryErr.Error())
|
|
|
- }
|
|
|
- log.Println("GetPhoneByToken:", sdkError.Message)
|
|
|
- return fmt.Errorf(*sdkError.Message), ""
|
|
|
- }
|
|
|
- return
|
|
|
- }()
|
|
|
- if err != nil || phone == "" {
|
|
|
- log.Println(err)
|
|
|
- return nil, err
|
|
|
- }
|
|
|
- // 手机号登录注册及绑定操作
|
|
|
- //data, err := o.ProcessPhone(phone)
|
|
|
- return o.ProcessPhone(phone)
|
|
|
+ //return fmt.Errorf(*_result.Body.Message), ""
|
|
|
+ }()
|
|
|
+ } else if o.AccessToken != "" {
|
|
|
+ getMobileRequest := &dypnsapi20170525.GetMobileRequest{
|
|
|
+ AccessToken: &o.AccessToken,
|
|
|
+ OutId: &o.OutId,
|
|
|
+ }
|
|
|
+ runtime := &util.RuntimeOptions{}
|
|
|
+ tryErr, phone = func() (_e error, p string) {
|
|
|
+ defer func() {
|
|
|
+ if r := tea.Recover(recover()); r != nil {
|
|
|
+ _e = r
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ // 复制代码运行请自行打印 API 的返回值
|
|
|
+ _result, _err := client.GetMobileWithOptions(getMobileRequest, runtime)
|
|
|
+ if _err != nil {
|
|
|
+ return _err, ""
|
|
|
+ }
|
|
|
+ if *_result.Body.Code == "OK" {
|
|
|
+ //获取手机号
|
|
|
+ return nil, *_result.Body.GetMobileResultDTO.Mobile
|
|
|
+ }
|
|
|
+ return fmt.Errorf(*_result.Body.Message), ""
|
|
|
+ }()
|
|
|
+ }
|
|
|
+ if tryErr != nil {
|
|
|
+ var sdkError = &tea.SDKError{}
|
|
|
+ if _t, ok := tryErr.(*tea.SDKError); ok {
|
|
|
+ sdkError = _t
|
|
|
+ } else {
|
|
|
+ sdkError.Message = tea.String(tryErr.Error())
|
|
|
+ }
|
|
|
+ log.Println("GetPhoneByToken:", sdkError.Message)
|
|
|
+ return fmt.Errorf(*sdkError.Message), ""
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }()
|
|
|
+ if err != nil || phone == "" {
|
|
|
+ log.Println(err)
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ // 手机号登录注册及绑定操作
|
|
|
+ //data, err := o.ProcessPhone(phone)
|
|
|
+ return o.ProcessPhone(phone)
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -171,694 +171,695 @@ func (o *OneClickInfo) GetPhoneByToken() (map[string]interface{}, error) {
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
func CreateClient() (_result *dypnsapi20170525.Client, _err error) {
|
|
|
- c := &openapi.Config{
|
|
|
- AccessKeyId: tea.String(initjson.OneClick.AccessKeyId),
|
|
|
- AccessKeySecret: tea.String(initjson.OneClick.AccessKeySecret),
|
|
|
- }
|
|
|
- c.Endpoint = tea.String("dypnsapi.aliyuncs.com")
|
|
|
- _result = &dypnsapi20170525.Client{}
|
|
|
- _result, _err = dypnsapi20170525.NewClient(c)
|
|
|
- return _result, _err
|
|
|
+ c := &openapi.Config{
|
|
|
+ AccessKeyId: tea.String(initjson.OneClick.AccessKeyId),
|
|
|
+ AccessKeySecret: tea.String(initjson.OneClick.AccessKeySecret),
|
|
|
+ }
|
|
|
+ c.Endpoint = tea.String("dypnsapi.aliyuncs.com")
|
|
|
+ _result = &dypnsapi20170525.Client{}
|
|
|
+ _result, _err = dypnsapi20170525.NewClient(c)
|
|
|
+ return _result, _err
|
|
|
}
|
|
|
|
|
|
type authToken struct {
|
|
|
- AccessToken string `json:"accessToken"`
|
|
|
- JwtToken string `json:"jwtToken"`
|
|
|
+ AccessToken string `json:"accessToken"`
|
|
|
+ JwtToken string `json:"jwtToken"`
|
|
|
}
|
|
|
|
|
|
func GetAuthTokenWithOptions(host string) (_err error, token *authToken) {
|
|
|
- // 判断是微信还是h5的域名
|
|
|
- origin, url, sceneCode := "", "", ""
|
|
|
- log.Println(initjson.OneClick.H5.Origin, "========", host)
|
|
|
- if strings.Contains(initjson.OneClick.H5.Origin, host) {
|
|
|
- origin = initjson.OneClick.H5.Origin
|
|
|
- url = initjson.OneClick.H5.Url
|
|
|
- sceneCode = initjson.OneClick.H5.SceneCode
|
|
|
- } else if strings.Contains(initjson.OneClick.Wx.Origin, host) {
|
|
|
- origin = initjson.OneClick.Wx.Origin
|
|
|
- url = initjson.OneClick.Wx.Url
|
|
|
- sceneCode = initjson.OneClick.Wx.SceneCode
|
|
|
- } else {
|
|
|
- log.Println("未匹配到host:", host)
|
|
|
- return errors.New("host未匹配到"), token
|
|
|
- }
|
|
|
- // 是否走缓存
|
|
|
- redisKey := fmt.Sprintf(initjson.OneClick.TokenCache.Key, host)
|
|
|
- if initjson.OneClick.TokenCache.Open {
|
|
|
- // 查缓存
|
|
|
- if reidsCatche, redisErr := redis.GetBytes("other", redisKey); redisErr == nil && reidsCatche != nil {
|
|
|
- errs := json.Unmarshal(*reidsCatche, &token)
|
|
|
- if errs == nil && token != nil {
|
|
|
- return nil, token
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- var (
|
|
|
- client *dypnsapi20170525.Client
|
|
|
- )
|
|
|
- token = &authToken{}
|
|
|
- client, _err = CreateClient()
|
|
|
- if _err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- getAuthTokenRequest := &dypnsapi20170525.GetAuthTokenRequest{
|
|
|
- Origin: tea.String(origin),
|
|
|
- Url: tea.String(url),
|
|
|
- SceneCode: tea.String(sceneCode),
|
|
|
- }
|
|
|
- runtime := &util.RuntimeOptions{}
|
|
|
- tryErr := func() (_e error) {
|
|
|
- defer func() {
|
|
|
- if r := tea.Recover(recover()); r != nil {
|
|
|
- _e = r
|
|
|
- }
|
|
|
- }()
|
|
|
- // 复制代码运行请自行打印 API 的返回值
|
|
|
- _result, _err := client.GetAuthTokenWithOptions(getAuthTokenRequest, runtime)
|
|
|
- log.Println(_result)
|
|
|
- if _err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- token.AccessToken = *_result.Body.TokenInfo.AccessToken
|
|
|
- token.JwtToken = *_result.Body.TokenInfo.JwtToken
|
|
|
- return
|
|
|
- }()
|
|
|
- if tryErr != nil {
|
|
|
- var sdkError = &tea.SDKError{}
|
|
|
- if _t, ok := tryErr.(*tea.SDKError); ok {
|
|
|
- sdkError = _t
|
|
|
- } else {
|
|
|
- sdkError.Message = tea.String(tryErr.Error())
|
|
|
- }
|
|
|
+ // 判断是微信还是h5的域名
|
|
|
+ origin, url, sceneCode := "", "", ""
|
|
|
+ log.Println(initjson.OneClick.H5.Origin, "========", host)
|
|
|
+ if strings.Contains(initjson.OneClick.H5.Origin, host) {
|
|
|
+ origin = initjson.OneClick.H5.Origin
|
|
|
+ url = initjson.OneClick.H5.Url
|
|
|
+ sceneCode = initjson.OneClick.H5.SceneCode
|
|
|
+ } else if strings.Contains(initjson.OneClick.Wx.Origin, host) {
|
|
|
+ origin = initjson.OneClick.Wx.Origin
|
|
|
+ url = initjson.OneClick.Wx.Url
|
|
|
+ sceneCode = initjson.OneClick.Wx.SceneCode
|
|
|
+ } else {
|
|
|
+ log.Println("未匹配到host:", host)
|
|
|
+ return errors.New("host未匹配到"), token
|
|
|
+ }
|
|
|
+ // 是否走缓存
|
|
|
+ redisKey := fmt.Sprintf(initjson.OneClick.TokenCache.Key, host)
|
|
|
+ if initjson.OneClick.TokenCache.Open {
|
|
|
+ // 查缓存
|
|
|
+ if reidsCatche, redisErr := redis.GetBytes("other", redisKey); redisErr == nil && reidsCatche != nil {
|
|
|
+ errs := json.Unmarshal(*reidsCatche, &token)
|
|
|
+ if errs == nil && token != nil {
|
|
|
+ return nil, token
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var (
|
|
|
+ client *dypnsapi20170525.Client
|
|
|
+ )
|
|
|
+ token = &authToken{}
|
|
|
+ client, _err = CreateClient()
|
|
|
+ if _err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ getAuthTokenRequest := &dypnsapi20170525.GetAuthTokenRequest{
|
|
|
+ Origin: tea.String(origin),
|
|
|
+ Url: tea.String(url),
|
|
|
+ SceneCode: tea.String(sceneCode),
|
|
|
+ }
|
|
|
+ runtime := &util.RuntimeOptions{}
|
|
|
+ tryErr := func() (_e error) {
|
|
|
+ defer func() {
|
|
|
+ if r := tea.Recover(recover()); r != nil {
|
|
|
+ _e = r
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ // 复制代码运行请自行打印 API 的返回值
|
|
|
+ _result, _err := client.GetAuthTokenWithOptions(getAuthTokenRequest, runtime)
|
|
|
+ log.Println(_result)
|
|
|
+ if _err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ token.AccessToken = *_result.Body.TokenInfo.AccessToken
|
|
|
+ token.JwtToken = *_result.Body.TokenInfo.JwtToken
|
|
|
+ return
|
|
|
+ }()
|
|
|
+ if tryErr != nil {
|
|
|
+ var sdkError = &tea.SDKError{}
|
|
|
+ if _t, ok := tryErr.(*tea.SDKError); ok {
|
|
|
+ sdkError = _t
|
|
|
+ } else {
|
|
|
+ sdkError.Message = tea.String(tryErr.Error())
|
|
|
+ }
|
|
|
|
|
|
- log.Println("GetAuthTokenWithOptions:", sdkError.Message)
|
|
|
+ log.Println("GetAuthTokenWithOptions:", sdkError.Message)
|
|
|
|
|
|
- }
|
|
|
- if initjson.OneClick.TokenCache.Open {
|
|
|
- // 存缓存
|
|
|
- if bytes, err := json.Marshal(token); err == nil && bytes != nil {
|
|
|
- _ = redis.PutBytes("other", redisKey, &bytes, initjson.OneClick.TokenCache.Timeout)
|
|
|
- }
|
|
|
- }
|
|
|
- return
|
|
|
+ }
|
|
|
+ if initjson.OneClick.TokenCache.Open {
|
|
|
+ // 存缓存
|
|
|
+ if bytes, err := json.Marshal(token); err == nil && bytes != nil {
|
|
|
+ _ = redis.PutBytes("other", redisKey, &bytes, initjson.OneClick.TokenCache.Timeout)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
func (o *OneClickInfo) ProcessPhone(phone string) (map[string]interface{}, error) {
|
|
|
- returnData := map[string]interface{}{}
|
|
|
- // 绑定
|
|
|
- if o.ActionType == "B" { // 绑定手机号
|
|
|
- token, err := o.bindPhone(phone, false)
|
|
|
- if err != nil {
|
|
|
- return nil, err
|
|
|
- } else if token != "" {
|
|
|
- returnData["state"] = 2
|
|
|
- returnData["token"] = token
|
|
|
- } else {
|
|
|
- returnData["state"] = 1
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 登录注册
|
|
|
- rs, err := o.phoneLogin(phone)
|
|
|
- if err != nil {
|
|
|
- return nil, err
|
|
|
- }
|
|
|
- returnData = rs
|
|
|
- }
|
|
|
- return returnData, nil
|
|
|
+ returnData := map[string]interface{}{}
|
|
|
+ // 绑定
|
|
|
+ if o.ActionType == "B" { // 绑定手机号
|
|
|
+ token, err := o.bindPhone(phone, false)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ } else if token != "" {
|
|
|
+ returnData["state"] = 2
|
|
|
+ returnData["token"] = token
|
|
|
+ } else {
|
|
|
+ returnData["state"] = 1
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 登录注册
|
|
|
+ rs, err := o.phoneLogin(phone)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ returnData = rs
|
|
|
+ }
|
|
|
+ return returnData, nil
|
|
|
}
|
|
|
|
|
|
// 绑定手机号
|
|
|
func (o *OneClickInfo) bindPhone(phone string, isAccountMerge bool) (string, error) {
|
|
|
- var (
|
|
|
- mgoUserId, _ = o.Session.Get("mgoUserId").(string)
|
|
|
- token = ""
|
|
|
- )
|
|
|
- if mgoUserId == "" {
|
|
|
- return token, errors.New("未登录")
|
|
|
- }
|
|
|
- if thisPhone, _ := o.Session.Get("phone").(string); thisPhone == "" {
|
|
|
- user, ok := db.Mgo.FindById("user", mgoUserId, `{"s_unionid":1}`)
|
|
|
- if !ok || user == nil {
|
|
|
- return token, errors.New("账号异常")
|
|
|
- }
|
|
|
- unionId, _ := (*user)["s_unionid"].(string)
|
|
|
- if unionId == "" {
|
|
|
- return token, errors.New("账号异常")
|
|
|
- }
|
|
|
- exists, relationPhoneId, _ := jy.NewPhoneUtil(db.Mgo).BindPhoneIsOccupy(mgoUserId, unionId, phone)
|
|
|
- if exists { //校验是否使用
|
|
|
- return token, errors.New(PhoneHasBind)
|
|
|
- }
|
|
|
- o.Session.Set("relationPhoneId", relationPhoneId)
|
|
|
- var err error
|
|
|
- token, err = AccountMerge(phone, "", mgoUserId, o.Session, isAccountMerge)
|
|
|
- mgoUserId, _ = o.Session.Get("mgoUserId").(string)
|
|
|
- go o.saveLog(mgoUserId, "o_bind")
|
|
|
- if err != nil {
|
|
|
- return token, err
|
|
|
- } else {
|
|
|
- jy.Publish(db.Mgo_Log, config.Config.Nsq, config.Config.NsqTopic, "task", mgoUserId, jy.Jyweb_node2, map[string]interface{}{
|
|
|
- "code": 1007,
|
|
|
- "types": "bindPhone",
|
|
|
- "num": 50,
|
|
|
- "baseUserId": o.Session.Get("base_user_id"),
|
|
|
- "positionId": o.Session.Get("positionId"),
|
|
|
- "isOnlyBind": true,
|
|
|
- })
|
|
|
- }
|
|
|
- } else {
|
|
|
- return token, errors.New("已绑定过手机号")
|
|
|
- }
|
|
|
- return token, nil
|
|
|
+ var (
|
|
|
+ mgoUserId, _ = o.Session.Get("mgoUserId").(string)
|
|
|
+ token = ""
|
|
|
+ )
|
|
|
+ if mgoUserId == "" {
|
|
|
+ return token, errors.New("未登录")
|
|
|
+ }
|
|
|
+ if thisPhone, _ := o.Session.Get("phone").(string); thisPhone == "" {
|
|
|
+ user, ok := db.Mgo.FindById("user", mgoUserId, `{"s_unionid":1}`)
|
|
|
+ if !ok || user == nil {
|
|
|
+ return token, errors.New("账号异常")
|
|
|
+ }
|
|
|
+ unionId, _ := (*user)["s_unionid"].(string)
|
|
|
+ if unionId == "" {
|
|
|
+ return token, errors.New("账号异常")
|
|
|
+ }
|
|
|
+ exists, relationPhoneId, _ := jy.NewPhoneUtil(db.Mgo).BindPhoneIsOccupy(mgoUserId, unionId, phone)
|
|
|
+ if exists { //校验是否使用
|
|
|
+ return token, errors.New(PhoneHasBind)
|
|
|
+ }
|
|
|
+ o.Session.Set("relationPhoneId", relationPhoneId)
|
|
|
+ var err error
|
|
|
+ token, err = AccountMerge(phone, "", mgoUserId, o.Session, isAccountMerge)
|
|
|
+ mgoUserId, _ = o.Session.Get("mgoUserId").(string)
|
|
|
+ go o.saveLog(mgoUserId, "o_bind")
|
|
|
+ if err != nil {
|
|
|
+ return token, err
|
|
|
+ } else {
|
|
|
+ jy.Publish(db.Mgo_Log, config.Config.Nsq, config.Config.NsqTopic, "task", mgoUserId, jy.Jyweb_node2, map[string]interface{}{
|
|
|
+ "code": 1007,
|
|
|
+ "types": "bindPhone",
|
|
|
+ "num": 50,
|
|
|
+ "baseUserId": o.Session.Get("base_user_id"),
|
|
|
+ "positionId": o.Session.Get("positionId"),
|
|
|
+ "isOnlyBind": true,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return token, errors.New("已绑定过手机号")
|
|
|
+ }
|
|
|
+ return token, nil
|
|
|
}
|
|
|
|
|
|
// 登录 注册
|
|
|
func (o *OneClickInfo) phoneLogin(phone string) (map[string]interface{}, error) {
|
|
|
- returnSign := ""
|
|
|
- userInfo := map[string]interface{}{}
|
|
|
- channelCode := ""
|
|
|
- loginCode := "jy_app_phone"
|
|
|
- platform := "app"
|
|
|
- if strings.Contains(o.Host, "h5.jianyu360.cn") {
|
|
|
- platform = "h5"
|
|
|
- loginCode = "jy_h5_phone"
|
|
|
- }
|
|
|
- cc, ckErr := o.R.Cookie(jy.ChannelCookieName)
|
|
|
- if ckErr == nil {
|
|
|
- channelCode = cc.Value
|
|
|
- }
|
|
|
- status := func() int {
|
|
|
- RegLock.Lock()
|
|
|
- reg := RegMap[phone]
|
|
|
- if reg == nil {
|
|
|
- reg = &RegStruct{}
|
|
|
- reg.Lock = sync.Mutex{}
|
|
|
- reg.MapR = make(map[string]int64)
|
|
|
- reg.MapR[phone] = time.Now().Unix()
|
|
|
- RegMap[phone] = reg
|
|
|
- }
|
|
|
- RegLock.Unlock()
|
|
|
- reg.Lock.Lock()
|
|
|
- defer reg.Lock.Unlock()
|
|
|
- ok, users := getPhoneUser(phone)
|
|
|
- if !ok {
|
|
|
- return 0
|
|
|
- }
|
|
|
- //用户不存在
|
|
|
- userPhone := common.InterfaceToStr(o.Session.Get("phone"))
|
|
|
- userId := common.InterfaceToStr(o.Session.Get("userId"))
|
|
|
- if userId != "" && userPhone == "" {
|
|
|
- if _, err := o.bindPhone(phone, true); err == nil {
|
|
|
- jy.JyAppCreateSession(db.Mgo, o.Session, userId, 0, *o.ResponseWriter, true, config.Middleground, config.Config.AppPushServiceRpc, config.Config.Criticality)
|
|
|
- if c := public.Mysql.CountBySql("SELECT count(1) FROM dataexport_order WHERE (user_id = ? OR user_phone = ?) AND distribution_channel = 'x054'", userId, phone); c > 0 {
|
|
|
- return -3
|
|
|
- } else {
|
|
|
- jy.Publish(db.Mgo_Log, config.Config.Nsq, config.Config.NsqTopic, "task", userId, jy.Jyweb_node2, map[string]interface{}{
|
|
|
- "code": 1007,
|
|
|
- "types": "bindPhone",
|
|
|
- "num": 50,
|
|
|
- "baseUserId": o.Session.Get("base_user_id"),
|
|
|
- "positionId": o.Session.Get("positionId"),
|
|
|
- "isOnlyBind": true,
|
|
|
- })
|
|
|
- }
|
|
|
- } else if err.Error() == PhoneHasBind {
|
|
|
- //已经绑定过手机号
|
|
|
- return -1
|
|
|
- }
|
|
|
- return 3
|
|
|
- }
|
|
|
- if users == nil || len(users) == 0 {
|
|
|
- client := o.UA
|
|
|
- log.Println(client)
|
|
|
- //clearRidByRid(rid)
|
|
|
- data := map[string]interface{}{
|
|
|
- "i_appid": 2,
|
|
|
- "s_phone": phone,
|
|
|
- "s_unique": phone,
|
|
|
- "s_password": "",
|
|
|
- "l_registedate": time.Now().Unix(),
|
|
|
- "s_jpushid": o.Rid,
|
|
|
- "s_opushid": o.Oid,
|
|
|
- "s_appponetype": o.PhoneType,
|
|
|
- "i_ts_guide": 2,
|
|
|
- "o_jy": map[string]interface{}{
|
|
|
- "i_apppush": 1,
|
|
|
- "i_ratemode": 2,
|
|
|
- "l_modifydate": time.Now().Unix(),
|
|
|
- },
|
|
|
- "s_platform": platform,
|
|
|
- "s_sourceid": channelCode,
|
|
|
- "s_rsource": channelCode,
|
|
|
- "s_reg_page": o.Session.Get("appLoginReferer"), //注册页面
|
|
|
- }
|
|
|
- sourceLabel := fx.GetVisitSource(o.Session) //common.InterfaceToStr(o.Session.Get("RSource")) //redis.GetStr("limitation", fmt.Sprintf("firstVisitTagByWX_%s", o.Session.Id()))
|
|
|
- if sourceLabel != "" {
|
|
|
- data["s_rsource"] = sourceLabel
|
|
|
- channelCode = sourceLabel
|
|
|
- }
|
|
|
- // 新注册用户
|
|
|
- if o.Activity != "" {
|
|
|
- data["s_rsource"] = o.Activity
|
|
|
- }
|
|
|
- data["s_regsource"] = isAndroidOrIOS(client)
|
|
|
+ returnSign := ""
|
|
|
+ userInfo := map[string]interface{}{}
|
|
|
+ channelCode := ""
|
|
|
+ loginCode := "jy_app_phone"
|
|
|
+ platform := "app"
|
|
|
+ if strings.Contains(o.Host, "h5.jianyu360.cn") {
|
|
|
+ platform = "h5"
|
|
|
+ loginCode = "jy_h5_phone"
|
|
|
+ }
|
|
|
+ cc, ckErr := o.R.Cookie(jy.ChannelCookieName)
|
|
|
+ if ckErr == nil {
|
|
|
+ channelCode = cc.Value
|
|
|
+ }
|
|
|
+ status := func() int {
|
|
|
+ RegLock.Lock()
|
|
|
+ reg := RegMap[phone]
|
|
|
+ if reg == nil {
|
|
|
+ reg = &RegStruct{}
|
|
|
+ reg.Lock = sync.Mutex{}
|
|
|
+ reg.MapR = make(map[string]int64)
|
|
|
+ reg.MapR[phone] = time.Now().Unix()
|
|
|
+ RegMap[phone] = reg
|
|
|
+ }
|
|
|
+ RegLock.Unlock()
|
|
|
+ reg.Lock.Lock()
|
|
|
+ defer reg.Lock.Unlock()
|
|
|
+ ok, users := getPhoneUser(phone)
|
|
|
+ if !ok {
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+ //用户不存在
|
|
|
+ userPhone := common.InterfaceToStr(o.Session.Get("phone"))
|
|
|
+ userId := common.InterfaceToStr(o.Session.Get("userId"))
|
|
|
+ if userId != "" && userPhone == "" {
|
|
|
+ if _, err := o.bindPhone(phone, true); err == nil {
|
|
|
+ jy.JyAppCreateSession(db.Mgo, o.Session, userId, 0, *o.ResponseWriter, true, config.Middleground, config.Config.AppPushServiceRpc, config.Config.Criticality)
|
|
|
+ if c := public.Mysql.CountBySql("SELECT count(1) FROM dataexport_order WHERE (user_id = ? OR user_phone = ?) AND distribution_channel = 'x054'", userId, phone); c > 0 {
|
|
|
+ return -3
|
|
|
+ } else {
|
|
|
+ jy.Publish(db.Mgo_Log, config.Config.Nsq, config.Config.NsqTopic, "task", userId, jy.Jyweb_node2, map[string]interface{}{
|
|
|
+ "code": 1007,
|
|
|
+ "types": "bindPhone",
|
|
|
+ "num": 50,
|
|
|
+ "baseUserId": o.Session.Get("base_user_id"),
|
|
|
+ "positionId": o.Session.Get("positionId"),
|
|
|
+ "isOnlyBind": true,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } else if err.Error() == PhoneHasBind {
|
|
|
+ //已经绑定过手机号
|
|
|
+ return -1
|
|
|
+ }
|
|
|
+ return 3
|
|
|
+ }
|
|
|
+ if users == nil || len(users) == 0 {
|
|
|
+ client := o.UA
|
|
|
+ log.Println(client)
|
|
|
+ //clearRidByRid(rid)
|
|
|
+ data := map[string]interface{}{
|
|
|
+ "i_appid": 2,
|
|
|
+ "s_phone": phone,
|
|
|
+ "s_unique": phone,
|
|
|
+ "s_password": "",
|
|
|
+ "l_registedate": time.Now().Unix(),
|
|
|
+ "s_jpushid": o.Rid,
|
|
|
+ "s_opushid": o.Oid,
|
|
|
+ "s_appponetype": o.PhoneType,
|
|
|
+ "i_ts_guide": 2,
|
|
|
+ "o_jy": map[string]interface{}{
|
|
|
+ "i_apppush": 1,
|
|
|
+ "i_ratemode": 2,
|
|
|
+ "l_modifydate": time.Now().Unix(),
|
|
|
+ },
|
|
|
+ "s_platform": platform,
|
|
|
+ "s_sourceid": channelCode,
|
|
|
+ "s_rsource": channelCode,
|
|
|
+ "s_reg_page": o.Session.Get("appLoginReferer"), //注册页面
|
|
|
+ }
|
|
|
+ sourceLabel := fx.GetVisitSource(o.Session) //common.InterfaceToStr(o.Session.Get("RSource")) //redis.GetStr("limitation", fmt.Sprintf("firstVisitTagByWX_%s", o.Session.Id()))
|
|
|
+ if sourceLabel != "" {
|
|
|
+ data["s_rsource"] = sourceLabel
|
|
|
+ channelCode = sourceLabel
|
|
|
+ }
|
|
|
+ // 新注册用户
|
|
|
+ if o.Activity != "" {
|
|
|
+ data["s_rsource"] = o.Activity
|
|
|
+ }
|
|
|
+ data["s_regsource"] = isAndroidOrIOS(client)
|
|
|
|
|
|
- _id := db.Mgo.Save("user", data)
|
|
|
- if _id != "" {
|
|
|
- //if sourceLabel != "" {
|
|
|
- // go func() {
|
|
|
- // redis.Del("limitation", fmt.Sprintf("firstVisitTagByWX_%s", o.Session.Id()))
|
|
|
- // }()
|
|
|
- //}
|
|
|
- userInfo["isNewUser"] = true
|
|
|
- referer := o.R.Referer()
|
|
|
- go jy.SaveUserLog(db.Mgo_Log, _id,
|
|
|
- phone,
|
|
|
- "phone",
|
|
|
- isAndroidOrIOS(client),
|
|
|
- platform,
|
|
|
- "",
|
|
|
- "",
|
|
|
- gconv.String(data["s_rsource"]),
|
|
|
- o.R.Proto,
|
|
|
- client,
|
|
|
- "",
|
|
|
- "",
|
|
|
- referer,
|
|
|
- "")
|
|
|
- //用户中台同步
|
|
|
- func(userid string) {
|
|
|
- if ok := jy.AddUser(db.Mgo, userid, pb.UserAddReq{
|
|
|
- Appid: "10000",
|
|
|
- Phone: phone,
|
|
|
- }, *config.Middleground); !ok {
|
|
|
- log.Println("usercenter add error", userid, phone)
|
|
|
- }
|
|
|
- }(_id)
|
|
|
- returnSign = afterLogin(data, o.Session, o.Rid, o.Oid, o.PhoneType, o.Channel, o.DeviceId, true, *o.ResponseWriter)
|
|
|
- addr := config.Config.Nsq
|
|
|
- nsq_topic := config.Config.NsqTopic
|
|
|
- if o.DisWord != "" {
|
|
|
- redisDis := redis.GetStr("other", "DIS_"+o.DisWord[1:])
|
|
|
- //邀请新用户 调用队列
|
|
|
- if redisDisArr := strings.Split(redisDis, "##"); len(redisDisArr) > 1 {
|
|
|
- fromUserId := redisDisArr[1]
|
|
|
- err := jy.Publish(db.Mgo_Log, addr, nsq_topic, jy.Jywx_subscribe_invite, fromUserId, jy.Jyapp_node1, nil)
|
|
|
- if err != nil {
|
|
|
- log.Println("nsq队列写入失败-->", err, jy.Jywx_subscribe_invite, fromUserId)
|
|
|
- }
|
|
|
- err = jy.Publish(db.Mgo_Log, addr, nsq_topic, jy.Jywx_subscribe_invited, _id, jy.Jyapp_node1, nil)
|
|
|
- if err != nil {
|
|
|
- log.Println("nsq队列写入失败-->", err, jy.Jywx_subscribe_invited, _id)
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- err := jy.Publish(db.Mgo_Log, addr, nsq_topic, jy.Jyapp_phone_register, _id, jy.Jyapp_node1, nil)
|
|
|
- if err != nil {
|
|
|
- log.Println("nsq队列写入失败-->", err, jy.Jyapp_phone_register, _id)
|
|
|
- }
|
|
|
- }
|
|
|
- mgoUserId, _ := o.Session.Get("mgoUserId").(string)
|
|
|
- go o.saveLog(mgoUserId, "o_register")
|
|
|
- return 2
|
|
|
- }
|
|
|
- } else {
|
|
|
- user := users[0]
|
|
|
- //以s_m_phone登录的 需要把s_m_phone转化为s_phone
|
|
|
- updataMap := map[string]interface{}{}
|
|
|
- if user["s_m_phone"] != nil {
|
|
|
- updataMap["s_phone"] = phone
|
|
|
- }
|
|
|
- if len(updataMap) > 0 {
|
|
|
- db.Mgo.UpdateById("user", mongodb.BsonIdToSId(user["_id"]), map[string]interface{}{
|
|
|
- "$set": updataMap,
|
|
|
- "$unset": map[string]interface{}{"s_m_phone": ""},
|
|
|
- })
|
|
|
- }
|
|
|
- returnSign = afterLogin(user, o.Session, o.Rid, o.Oid, o.PhoneType, o.Channel, o.DeviceId, false, *o.ResponseWriter)
|
|
|
- mgoUserId, _ := o.Session.Get("mgoUserId").(string)
|
|
|
- go o.saveLog(mgoUserId, "o_login")
|
|
|
- return 1
|
|
|
- }
|
|
|
- return 0
|
|
|
- }()
|
|
|
- if status > 0 {
|
|
|
- //登录 注册后 清除合作商来源标识
|
|
|
- if channelCode != "" {
|
|
|
- pu.ClearCookie(*o.ResponseWriter, jy.ChannelCookieName)
|
|
|
- }
|
|
|
- //mgoUserId := qutil.ObjToString(o.Session.Get("mgoUserId"))
|
|
|
- mgoUserId, _ := o.Session.Get("mgoUserId").(string)
|
|
|
- err := jy.Publish(db.Mgo_Log, config.Config.Nsq, config.Config.NsqTopic, "task", mgoUserId, "", map[string]interface{}{
|
|
|
- "code": 1014, //下载app任务
|
|
|
- "types": "downloadApp",
|
|
|
- "num": 50,
|
|
|
- "baseUserId": o.Session.Get("base_user_id"),
|
|
|
- "positionId": o.Session.Get("positionId"),
|
|
|
- })
|
|
|
- if err != nil {
|
|
|
- log.Println(mgoUserId, "下载app任务,发送nsq消息错误-->", err)
|
|
|
- }
|
|
|
- //登录source 更新 p414
|
|
|
- phone, _ := o.Session.Get("phone").(string)
|
|
|
- //positionId, _ := o.Session.Get("positionId").(int64)
|
|
|
- positionId := common.Int64All(o.Session.Get("positionId"))
|
|
|
- us := jy.UserSource{
|
|
|
- UserId: mgoUserId,
|
|
|
- PositionId: positionId,
|
|
|
- Phone: phone,
|
|
|
- State: status, //注册/登录标志 1:登录;2:注册
|
|
|
- ChannelCode: channelCode,
|
|
|
- EncryptionUserId: encrypt.SE.EncodeString(mgoUserId),
|
|
|
- CreateTime: time.Now().Format(date.Date_Full_Layout),
|
|
|
- LoginCode: loginCode,
|
|
|
- LoginWay: 4, //登录方式;1:手机号密码;2:手机号验证码;3:微信;4:手机号一键登录
|
|
|
- Platform: common.If(strings.Contains(o.Host, "h5.jianyu360.cn"), 4, 3).(int), //登录端;1:PC;2:WX;3:APP;4:H5
|
|
|
- Ip: common.GetIp(o.R),
|
|
|
- }
|
|
|
- go func(us jy.UserSource) {
|
|
|
- jy.SaveUserSource(public.BaseMysql, jy.ChannelTableName, common.StructToMapMore(us))
|
|
|
- }(us)
|
|
|
- status = gconv.Int(common.If(status <= 2, 1, status))
|
|
|
- }
|
|
|
- result := map[string]interface{}{
|
|
|
- "status": status,
|
|
|
- "userId": o.Session.Get("mgoUserId"),
|
|
|
- }
|
|
|
- if returnSign != "" {
|
|
|
- result["sign"] = returnSign
|
|
|
- }
|
|
|
- if len(userInfo) > 0 {
|
|
|
- result["userInfo"] = userInfo
|
|
|
- }
|
|
|
- return result, nil
|
|
|
+ _id := db.Mgo.Save("user", data)
|
|
|
+ if _id != "" {
|
|
|
+ //if sourceLabel != "" {
|
|
|
+ // go func() {
|
|
|
+ // redis.Del("limitation", fmt.Sprintf("firstVisitTagByWX_%s", o.Session.Id()))
|
|
|
+ // }()
|
|
|
+ //}
|
|
|
+ userInfo["isNewUser"] = true
|
|
|
+ referer := o.R.Referer()
|
|
|
+ go jy.SaveUserLog(db.Mgo_Log, _id,
|
|
|
+ phone,
|
|
|
+ "phone",
|
|
|
+ isAndroidOrIOS(client),
|
|
|
+ platform,
|
|
|
+ "",
|
|
|
+ "",
|
|
|
+ gconv.String(data["s_rsource"]),
|
|
|
+ o.R.Proto,
|
|
|
+ client,
|
|
|
+ "",
|
|
|
+ "",
|
|
|
+ referer,
|
|
|
+ "")
|
|
|
+ //用户中台同步
|
|
|
+ func(userid string) {
|
|
|
+ if ok := jy.AddUser(db.Mgo, userid, pb.UserAddReq{
|
|
|
+ Appid: "10000",
|
|
|
+ Phone: phone,
|
|
|
+ }, *config.Middleground); !ok {
|
|
|
+ log.Println("usercenter add error", userid, phone)
|
|
|
+ }
|
|
|
+ }(_id)
|
|
|
+ returnSign = afterLogin(data, o.Session, o.Rid, o.Oid, o.PhoneType, o.Channel, o.DeviceId, true, *o.ResponseWriter)
|
|
|
+ addr := config.Config.Nsq
|
|
|
+ nsq_topic := config.Config.NsqTopic
|
|
|
+ if o.DisWord != "" {
|
|
|
+ redisDis := redis.GetStr("other", "DIS_"+o.DisWord[1:])
|
|
|
+ //邀请新用户 调用队列
|
|
|
+ if redisDisArr := strings.Split(redisDis, "##"); len(redisDisArr) > 1 {
|
|
|
+ fromUserId := redisDisArr[1]
|
|
|
+ err := jy.Publish(db.Mgo_Log, addr, nsq_topic, jy.Jywx_subscribe_invite, fromUserId, jy.Jyapp_node1, nil)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("nsq队列写入失败-->", err, jy.Jywx_subscribe_invite, fromUserId)
|
|
|
+ }
|
|
|
+ err = jy.Publish(db.Mgo_Log, addr, nsq_topic, jy.Jywx_subscribe_invited, _id, jy.Jyapp_node1, nil)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("nsq队列写入失败-->", err, jy.Jywx_subscribe_invited, _id)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ err := jy.Publish(db.Mgo_Log, addr, nsq_topic, jy.Jyapp_phone_register, _id, jy.Jyapp_node1, nil)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("nsq队列写入失败-->", err, jy.Jyapp_phone_register, _id)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ mgoUserId, _ := o.Session.Get("mgoUserId").(string)
|
|
|
+ go o.saveLog(mgoUserId, "o_register")
|
|
|
+ return 2
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ user := users[0]
|
|
|
+ //以s_m_phone登录的 需要把s_m_phone转化为s_phone
|
|
|
+ updataMap := map[string]interface{}{}
|
|
|
+ if user["s_m_phone"] != nil {
|
|
|
+ updataMap["s_phone"] = phone
|
|
|
+ }
|
|
|
+ if len(updataMap) > 0 {
|
|
|
+ db.Mgo.UpdateById("user", mongodb.BsonIdToSId(user["_id"]), map[string]interface{}{
|
|
|
+ "$set": updataMap,
|
|
|
+ "$unset": map[string]interface{}{"s_m_phone": ""},
|
|
|
+ })
|
|
|
+ }
|
|
|
+ returnSign = afterLogin(user, o.Session, o.Rid, o.Oid, o.PhoneType, o.Channel, o.DeviceId, false, *o.ResponseWriter)
|
|
|
+ mgoUserId, _ := o.Session.Get("mgoUserId").(string)
|
|
|
+ go o.saveLog(mgoUserId, "o_login")
|
|
|
+ return 1
|
|
|
+ }
|
|
|
+ return 0
|
|
|
+ }()
|
|
|
+ if status > 0 {
|
|
|
+ //登录 注册后 清除合作商来源标识
|
|
|
+ if channelCode != "" {
|
|
|
+ pu.ClearCookie(*o.ResponseWriter, jy.ChannelCookieName)
|
|
|
+ }
|
|
|
+ //mgoUserId := qutil.ObjToString(o.Session.Get("mgoUserId"))
|
|
|
+ mgoUserId, _ := o.Session.Get("mgoUserId").(string)
|
|
|
+ err := jy.Publish(db.Mgo_Log, config.Config.Nsq, config.Config.NsqTopic, "task", mgoUserId, "", map[string]interface{}{
|
|
|
+ "code": 1014, //下载app任务
|
|
|
+ "types": "downloadApp",
|
|
|
+ "num": 50,
|
|
|
+ "baseUserId": o.Session.Get("base_user_id"),
|
|
|
+ "positionId": o.Session.Get("positionId"),
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ log.Println(mgoUserId, "下载app任务,发送nsq消息错误-->", err)
|
|
|
+ }
|
|
|
+ //登录source 更新 p414
|
|
|
+ phone, _ := o.Session.Get("phone").(string)
|
|
|
+ //positionId, _ := o.Session.Get("positionId").(int64)
|
|
|
+ positionId := common.Int64All(o.Session.Get("positionId"))
|
|
|
+ us := jy.UserSource{
|
|
|
+ UserId: mgoUserId,
|
|
|
+ PositionId: positionId,
|
|
|
+ Phone: phone,
|
|
|
+ State: status, //注册/登录标志 1:登录;2:注册
|
|
|
+ ChannelCode: channelCode,
|
|
|
+ EncryptionUserId: encrypt.SE.EncodeString(mgoUserId),
|
|
|
+ CreateTime: time.Now().Format(date.Date_Full_Layout),
|
|
|
+ LoginCode: loginCode,
|
|
|
+ LoginWay: 4, //登录方式;1:手机号密码;2:手机号验证码;3:微信;4:手机号一键登录
|
|
|
+ Platform: common.If(strings.Contains(o.Host, "h5.jianyu360.cn"), 4, 3).(int), //登录端;1:PC;2:WX;3:APP;4:H5
|
|
|
+ Ip: common.GetIp(o.R),
|
|
|
+ }
|
|
|
+ go func(us jy.UserSource) {
|
|
|
+ jy.SaveUserSource(public.BaseMysql, jy.ChannelTableName, common.StructToMapMore(us))
|
|
|
+ }(us)
|
|
|
+ status = gconv.Int(common.If(status <= 2, 1, status))
|
|
|
+ }
|
|
|
+ result := map[string]interface{}{
|
|
|
+ "status": status,
|
|
|
+ "userId": o.Session.Get("mgoUserId"),
|
|
|
+ }
|
|
|
+ if returnSign != "" {
|
|
|
+ result["sign"] = returnSign
|
|
|
+ }
|
|
|
+ if len(userInfo) > 0 {
|
|
|
+ result["userInfo"] = userInfo
|
|
|
+ }
|
|
|
+ return result, nil
|
|
|
}
|
|
|
|
|
|
// 绑定
|
|
|
func AccountMerge(phone, email, mgoUserId string, sess *httpsession.Session, isAccountMerge bool) (token string, err error) {
|
|
|
- if userinfo := config.Compatible.Select(mgoUserId, `{"s_unionid":1,"s_name":1,"s_nickname":1,"s_headimageurl":1,"l_registedate":1,"i_ispush":1,"i_applystatus":1,"i_sex":1,"s_country":1,"s_province":1,"s_city":1,"s_m_openid":1,"a_m_openid":1,"base_user_id":1,"s_newsource":1,"l_registedate":1}`); userinfo != nil && len(*userinfo) > 0 {
|
|
|
- //新用户时间
|
|
|
- onLineTime, _ := time.ParseInLocation(date.Date_Full_Layout, config.Config.AccountMergeOnline, time.Local)
|
|
|
- registerDate := common.Int64All((*userinfo)["l_registedate"])
|
|
|
- reg := time.Unix(registerDate, 0)
|
|
|
- relationPhoneId, _ := sess.Get("relationPhoneId").(string)
|
|
|
- //新账号
|
|
|
- if relationPhoneId == "" {
|
|
|
- data := map[string]interface{}{
|
|
|
- "s_unionid": (*userinfo)["s_unionid"],
|
|
|
- "s_name": (*userinfo)["s_name"],
|
|
|
- "s_nickname": (*userinfo)["s_nickname"],
|
|
|
- "s_headimageurl": (*userinfo)["s_headimageurl"],
|
|
|
- }
|
|
|
- if jy.IsEmail(email) {
|
|
|
- data["s_email"] = email
|
|
|
- }
|
|
|
- //建立关联关系
|
|
|
- if bindErr := jy.NewPhoneUtil(db.Mgo).BindPhone(mgoUserId, relationPhoneId, phone, email, &data); bindErr != nil {
|
|
|
- log.Println("bind link err :", bindErr)
|
|
|
- return "", bindErr
|
|
|
- } else {
|
|
|
- //用户中台存储 开始
|
|
|
- if uinfo := jy.GetInfoForBaseUser(db.Mgo, mgoUserId); uinfo != nil {
|
|
|
- jy.UpdateUser(db.Mgo, mgoUserId, *uinfo, *config.Middleground)
|
|
|
- } else {
|
|
|
- log.Println("--用户中台存储 异常--")
|
|
|
- }
|
|
|
- //用户中台存储 结束
|
|
|
- jy.CreateUserMerge(db.Mgo, db.Mysql, sess, config.Middleground).FlushSession(mgoUserId) //刷新session
|
|
|
- }
|
|
|
- } else if isAccountMerge || onLineTime.Before(reg) { //新微信用户直接绑定
|
|
|
- data := map[string]interface{}{
|
|
|
- "s_unionid": (*userinfo)["s_unionid"],
|
|
|
- "s_name": (*userinfo)["s_name"],
|
|
|
- "s_nickname": (*userinfo)["s_nickname"],
|
|
|
- "s_headimageurl": (*userinfo)["s_headimageurl"],
|
|
|
- "i_ispush": (*userinfo)["i_ispush"],
|
|
|
- "i_applystatus": (*userinfo)["i_applystatus"],
|
|
|
- "i_sex": (*userinfo)["i_sex"],
|
|
|
- "s_country": (*userinfo)["s_country"],
|
|
|
- "s_province": (*userinfo)["s_province"],
|
|
|
- "s_city": (*userinfo)["s_country"],
|
|
|
- "s_m_openid": (*userinfo)["s_m_openid"],
|
|
|
- "a_m_openid": (*userinfo)["a_m_openid"],
|
|
|
- "o_jy.i_wxpush": 1,
|
|
|
- }
|
|
|
- if jy.IsEmail(email) {
|
|
|
- data["s_email"] = email
|
|
|
- }
|
|
|
- if config.Compatible.Update(relationPhoneId, map[string]interface{}{
|
|
|
- "$set": data,
|
|
|
- }) {
|
|
|
- //用户中台存储 开始
|
|
|
- if uinfo := jy.GetInfoForBaseUser(db.Mgo, mongodb.BsonIdToSId(relationPhoneId)); uinfo != nil {
|
|
|
- jy.UpdateUser(db.Mgo, mongodb.BsonIdToSId(relationPhoneId), *uinfo, *config.Middleground)
|
|
|
- }
|
|
|
- //删除user
|
|
|
- base_userid_del := usercenter.GetBaseUserId(db.Mgo, mgoUserId)
|
|
|
- jy.DelUser(db.Mgo, mgoUserId, pb.UserIdReq{
|
|
|
- Appid: "10000",
|
|
|
- Id: base_userid_del,
|
|
|
- }, *config.Middleground)
|
|
|
- //备份用户
|
|
|
- if backUser, _ := db.Mgo.FindById("user", mgoUserId, nil); backUser != nil && len(*backUser) > 0 {
|
|
|
- backData := map[string]interface{}{
|
|
|
- "l_mergeData": time.Now().Unix(),
|
|
|
- "s_userId": mgoUserId,
|
|
|
- "s_save_userId": relationPhoneId,
|
|
|
- "mergeType": "autoMerge",
|
|
|
- }
|
|
|
- for k, v := range *backUser {
|
|
|
- if k == "_id" {
|
|
|
- continue
|
|
|
- }
|
|
|
- backData[k] = v
|
|
|
- }
|
|
|
- if db.Mgo.Save("user_merge", backData) != "" {
|
|
|
- db.Mgo.Del("user", map[string]interface{}{"_id": mongodb.StringTOBsonId(mgoUserId)})
|
|
|
- jy.CreateUserMerge(db.Mgo, db.Mysql, sess, config.Middleground).FlushSession(relationPhoneId)
|
|
|
- redis.Put("session", fmt.Sprintf("usermerge_delete_%s", mgoUserId), relationPhoneId, 7*24*60*60)
|
|
|
- } else {
|
|
|
- log.Println("备份用户查询异常")
|
|
|
- return "", errors.New("备份用户查询异常")
|
|
|
- }
|
|
|
- } else {
|
|
|
- log.Println("没有备份用户或备份用户查询异常")
|
|
|
- return "", errors.New("没有备份用户或备份用户查询异常")
|
|
|
- }
|
|
|
- } else {
|
|
|
- log.Println("账号 中台 更新异常")
|
|
|
- return "", errors.New("账号 中台 更新异常")
|
|
|
- }
|
|
|
- } else { //老微信用户选择合并
|
|
|
- go CollectPhone(mgoUserId, phone) //增加user表验证手机号
|
|
|
- token = jy.MergeEncrypt.Encode2Hex(mgoUserId + "&&" + relationPhoneId)
|
|
|
- }
|
|
|
- }
|
|
|
- return
|
|
|
+ if userinfo := config.Compatible.Select(mgoUserId, `{"s_unionid":1,"s_name":1,"s_nickname":1,"s_headimageurl":1,"l_registedate":1,"i_ispush":1,"i_applystatus":1,"i_sex":1,"s_country":1,"s_province":1,"s_city":1,"s_m_openid":1,"a_m_openid":1,"base_user_id":1,"s_newsource":1,"l_registedate":1,"s_rsource":1}`); userinfo != nil && len(*userinfo) > 0 {
|
|
|
+ //新用户时间
|
|
|
+ onLineTime, _ := time.ParseInLocation(date.Date_Full_Layout, config.Config.AccountMergeOnline, time.Local)
|
|
|
+ registerDate := common.Int64All((*userinfo)["l_registedate"])
|
|
|
+ reg := time.Unix(registerDate, 0)
|
|
|
+ relationPhoneId, _ := sess.Get("relationPhoneId").(string)
|
|
|
+ //新账号
|
|
|
+ if relationPhoneId == "" {
|
|
|
+ data := map[string]interface{}{
|
|
|
+ "s_unionid": (*userinfo)["s_unionid"],
|
|
|
+ "s_name": (*userinfo)["s_name"],
|
|
|
+ "s_nickname": (*userinfo)["s_nickname"],
|
|
|
+ "s_headimageurl": (*userinfo)["s_headimageurl"],
|
|
|
+ "s_rsource": (*userinfo)["s_rsource"],
|
|
|
+ }
|
|
|
+ if jy.IsEmail(email) {
|
|
|
+ data["s_email"] = email
|
|
|
+ }
|
|
|
+ //建立关联关系
|
|
|
+ if bindErr := jy.NewPhoneUtil(db.Mgo).BindPhone(mgoUserId, relationPhoneId, phone, email, &data); bindErr != nil {
|
|
|
+ log.Println("bind link err :", bindErr)
|
|
|
+ return "", bindErr
|
|
|
+ } else {
|
|
|
+ //用户中台存储 开始
|
|
|
+ if uinfo := jy.GetInfoForBaseUser(db.Mgo, mgoUserId); uinfo != nil {
|
|
|
+ jy.UpdateUser(db.Mgo, mgoUserId, *uinfo, *config.Middleground)
|
|
|
+ } else {
|
|
|
+ log.Println("--用户中台存储 异常--")
|
|
|
+ }
|
|
|
+ //用户中台存储 结束
|
|
|
+ jy.CreateUserMerge(db.Mgo, db.Mysql, sess, config.Middleground).FlushSession(mgoUserId) //刷新session
|
|
|
+ }
|
|
|
+ } else if isAccountMerge || onLineTime.Before(reg) { //新微信用户直接绑定
|
|
|
+ data := map[string]interface{}{
|
|
|
+ "s_unionid": (*userinfo)["s_unionid"],
|
|
|
+ "s_name": (*userinfo)["s_name"],
|
|
|
+ "s_nickname": (*userinfo)["s_nickname"],
|
|
|
+ "s_headimageurl": (*userinfo)["s_headimageurl"],
|
|
|
+ "i_ispush": (*userinfo)["i_ispush"],
|
|
|
+ "i_applystatus": (*userinfo)["i_applystatus"],
|
|
|
+ "i_sex": (*userinfo)["i_sex"],
|
|
|
+ "s_country": (*userinfo)["s_country"],
|
|
|
+ "s_province": (*userinfo)["s_province"],
|
|
|
+ "s_city": (*userinfo)["s_country"],
|
|
|
+ "s_m_openid": (*userinfo)["s_m_openid"],
|
|
|
+ "a_m_openid": (*userinfo)["a_m_openid"],
|
|
|
+ "o_jy.i_wxpush": 1,
|
|
|
+ }
|
|
|
+ if jy.IsEmail(email) {
|
|
|
+ data["s_email"] = email
|
|
|
+ }
|
|
|
+ if config.Compatible.Update(relationPhoneId, map[string]interface{}{
|
|
|
+ "$set": data,
|
|
|
+ }) {
|
|
|
+ //用户中台存储 开始
|
|
|
+ if uinfo := jy.GetInfoForBaseUser(db.Mgo, mongodb.BsonIdToSId(relationPhoneId)); uinfo != nil {
|
|
|
+ jy.UpdateUser(db.Mgo, mongodb.BsonIdToSId(relationPhoneId), *uinfo, *config.Middleground)
|
|
|
+ }
|
|
|
+ //删除user
|
|
|
+ base_userid_del := usercenter.GetBaseUserId(db.Mgo, mgoUserId)
|
|
|
+ jy.DelUser(db.Mgo, mgoUserId, pb.UserIdReq{
|
|
|
+ Appid: "10000",
|
|
|
+ Id: base_userid_del,
|
|
|
+ }, *config.Middleground)
|
|
|
+ //备份用户
|
|
|
+ if backUser, _ := db.Mgo.FindById("user", mgoUserId, nil); backUser != nil && len(*backUser) > 0 {
|
|
|
+ backData := map[string]interface{}{
|
|
|
+ "l_mergeData": time.Now().Unix(),
|
|
|
+ "s_userId": mgoUserId,
|
|
|
+ "s_save_userId": relationPhoneId,
|
|
|
+ "mergeType": "autoMerge",
|
|
|
+ }
|
|
|
+ for k, v := range *backUser {
|
|
|
+ if k == "_id" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ backData[k] = v
|
|
|
+ }
|
|
|
+ if db.Mgo.Save("user_merge", backData) != "" {
|
|
|
+ db.Mgo.Del("user", map[string]interface{}{"_id": mongodb.StringTOBsonId(mgoUserId)})
|
|
|
+ jy.CreateUserMerge(db.Mgo, db.Mysql, sess, config.Middleground).FlushSession(relationPhoneId)
|
|
|
+ redis.Put("session", fmt.Sprintf("usermerge_delete_%s", mgoUserId), relationPhoneId, 7*24*60*60)
|
|
|
+ } else {
|
|
|
+ log.Println("备份用户查询异常")
|
|
|
+ return "", errors.New("备份用户查询异常")
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.Println("没有备份用户或备份用户查询异常")
|
|
|
+ return "", errors.New("没有备份用户或备份用户查询异常")
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.Println("账号 中台 更新异常")
|
|
|
+ return "", errors.New("账号 中台 更新异常")
|
|
|
+ }
|
|
|
+ } else { //老微信用户选择合并
|
|
|
+ go CollectPhone(mgoUserId, phone) //增加user表验证手机号
|
|
|
+ token = jy.MergeEncrypt.Encode2Hex(mgoUserId + "&&" + relationPhoneId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
func CollectPhone(userId, phone string) bool {
|
|
|
- if userId == "" || phone == "" {
|
|
|
- return false
|
|
|
- }
|
|
|
- if !config.Compatible.Update(userId, map[string]interface{}{
|
|
|
- "$addToSet": map[string]interface{}{
|
|
|
- "a_collect_phone": phone,
|
|
|
- },
|
|
|
- }) {
|
|
|
- return false
|
|
|
- }
|
|
|
- return true
|
|
|
+ if userId == "" || phone == "" {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if !config.Compatible.Update(userId, map[string]interface{}{
|
|
|
+ "$addToSet": map[string]interface{}{
|
|
|
+ "a_collect_phone": phone,
|
|
|
+ },
|
|
|
+ }) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ return true
|
|
|
}
|
|
|
|
|
|
func getPhoneUser(phone string) (bool, []map[string]interface{}) {
|
|
|
- users, ok := db.Mgo.Find("user", map[string]interface{}{
|
|
|
- "i_appid": 2,
|
|
|
- "$or": []map[string]interface{}{
|
|
|
- {"s_phone": phone},
|
|
|
- {"s_m_phone": phone}},
|
|
|
- }, `{"s_phone":-1}`, nil, false, 0, 1)
|
|
|
- if users != nil && len(*users) > 0 {
|
|
|
- return ok, *users
|
|
|
- }
|
|
|
- return ok, nil
|
|
|
+ users, ok := db.Mgo.Find("user", map[string]interface{}{
|
|
|
+ "i_appid": 2,
|
|
|
+ "$or": []map[string]interface{}{
|
|
|
+ {"s_phone": phone},
|
|
|
+ {"s_m_phone": phone}},
|
|
|
+ }, `{"s_phone":-1}`, nil, false, 0, 1)
|
|
|
+ if users != nil && len(*users) > 0 {
|
|
|
+ return ok, *users
|
|
|
+ }
|
|
|
+ return ok, nil
|
|
|
}
|
|
|
|
|
|
type RegStruct struct {
|
|
|
- MapR map[string]int64
|
|
|
- Lock sync.Mutex
|
|
|
+ MapR map[string]int64
|
|
|
+ Lock sync.Mutex
|
|
|
}
|
|
|
|
|
|
func (this *RegStruct) GC() {
|
|
|
- defer common.Catch()
|
|
|
- this.Lock.Lock()
|
|
|
- now := time.Now().Unix()
|
|
|
- for k, v := range this.MapR {
|
|
|
- if now-v > 60 {
|
|
|
- reg := RegMap[k]
|
|
|
- if reg != nil {
|
|
|
- delete(RegMap, k)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- this.Lock.Unlock()
|
|
|
- time.AfterFunc(5*time.Minute, this.GC)
|
|
|
+ defer common.Catch()
|
|
|
+ this.Lock.Lock()
|
|
|
+ now := time.Now().Unix()
|
|
|
+ for k, v := range this.MapR {
|
|
|
+ if now-v > 60 {
|
|
|
+ reg := RegMap[k]
|
|
|
+ if reg != nil {
|
|
|
+ delete(RegMap, k)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.Lock.Unlock()
|
|
|
+ time.AfterFunc(5*time.Minute, this.GC)
|
|
|
}
|
|
|
|
|
|
func isAndroidOrIOS(s string) string {
|
|
|
- typ := ""
|
|
|
- if strings.Contains(s, "Android") {
|
|
|
- typ = "Android"
|
|
|
- } else if strings.Contains(s, "iPhone") || strings.Contains(s, "iPad") {
|
|
|
- typ = "IOS"
|
|
|
- } else {
|
|
|
- typ = "other"
|
|
|
- }
|
|
|
- return typ
|
|
|
+ typ := ""
|
|
|
+ if strings.Contains(s, "Android") {
|
|
|
+ typ = "Android"
|
|
|
+ } else if strings.Contains(s, "iPhone") || strings.Contains(s, "iPad") {
|
|
|
+ typ = "IOS"
|
|
|
+ } else {
|
|
|
+ typ = "other"
|
|
|
+ }
|
|
|
+ return typ
|
|
|
}
|
|
|
|
|
|
func afterLogin(user map[string]interface{}, session *httpsession.Session, rid, oid, phoneType, channel, deviceId string, isNewUser bool, rw http.ResponseWriter) string {
|
|
|
- userid := mongodb.BsonIdToSId(user["_id"])
|
|
|
- old_rid, _ := user["s_jpushid"].(string)
|
|
|
- old_oid, _ := user["s_opushid"].(string)
|
|
|
- old_ponetype, _ := user["s_appponetype"].(string)
|
|
|
- off := true
|
|
|
- log.Println("多账号登录:", user)
|
|
|
- go func() {
|
|
|
- if !isNewUser {
|
|
|
- if rd := config.Compatible.Select(userid, `{"i_unlimited":1}`); rd != nil && len(*rd) > 0 {
|
|
|
- i_unlimited := common.IntAll((*rd)["i_unlimited"])
|
|
|
- if i_unlimited > 0 {
|
|
|
- off = false
|
|
|
- }
|
|
|
- }
|
|
|
- log.Println("publicapply:", old_rid, "---", old_oid, "---", rid, "---", off)
|
|
|
- //同一账号在不同设备登录,极光id不一样,给之前的设备推送自定义的下线消息,离线消息保持10天
|
|
|
- if old_rid != "" && old_rid != rid && off && rid != "" {
|
|
|
- db.Mgo.UpdateById("user", userid, map[string]interface{}{
|
|
|
- "$addToSet": map[string]interface{}{"a_jpushid": old_rid},
|
|
|
- })
|
|
|
- //
|
|
|
- log.Println(userid, phoneType, rid, oid, "踢人下线", old_ponetype, old_rid, old_oid)
|
|
|
- qrpc.AppPush(config.Config.AppPushServiceRpc, map[string]interface{}{
|
|
|
- "type": "signOut",
|
|
|
- "descript": kickedTip,
|
|
|
- "jgPushId": old_rid,
|
|
|
- "otherPushId": old_oid,
|
|
|
- "phoneType": old_ponetype,
|
|
|
- "userId": userid,
|
|
|
- })
|
|
|
- }
|
|
|
- if channel != "" && deviceId != "" {
|
|
|
- //更新用户最后一次登录渠道和设备信息
|
|
|
- if db.Mgo.Count("jyapp_channel", map[string]interface{}{"s_userid": userid, "s_type": "lastLogin"}) > 0 {
|
|
|
- update := map[string]interface{}{"i_cometime": time.Now().Unix(), "s_channel": channel}
|
|
|
- db.Mgo.Update("jyapp_channel", map[string]interface{}{"s_userid": userid, "s_type": "lastLogin"},
|
|
|
- map[string]interface{}{"$set": update}, false, true)
|
|
|
- } else {
|
|
|
- db.Mgo.Save("jyapp_channel", map[string]interface{}{
|
|
|
- "s_deviceId": deviceId,
|
|
|
- "s_type": "lastLogin",
|
|
|
- "i_cometime": time.Now().Unix(),
|
|
|
- "s_channel": channel,
|
|
|
- "s_userid": userid,
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- if channel != "" && deviceId != "" {
|
|
|
- //记录新用户注册渠道来源
|
|
|
- db.Mgo.Save("jyapp_channel", map[string]interface{}{
|
|
|
- "s_deviceId": deviceId,
|
|
|
- "s_type": "regist",
|
|
|
- "i_cometime": time.Now().Unix(),
|
|
|
- "s_channel": channel,
|
|
|
- "s_userid": userid,
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
- if rid != "" {
|
|
|
- db.Mgo.Update("user", map[string]interface{}{
|
|
|
- "i_appid": 2,
|
|
|
- "s_jpushid": rid,
|
|
|
- }, map[string]interface{}{
|
|
|
- "$unset": map[string]interface{}{
|
|
|
- "s_jpushid": "",
|
|
|
- "s_opushid": "",
|
|
|
- },
|
|
|
- }, false, true)
|
|
|
- set := map[string]interface{}{
|
|
|
- "s_jpushid": rid,
|
|
|
- "s_opushid": oid,
|
|
|
- "s_appponetype": phoneType,
|
|
|
- }
|
|
|
- if o_jy, ok := user["o_jy"].(map[string]interface{}); ok && o_jy != nil && o_jy["i_apppush"] == nil {
|
|
|
- set["o_jy.i_apppush"] = 1
|
|
|
- }
|
|
|
- db.Mgo.UpdateById("user", userid, map[string]interface{}{
|
|
|
- "$set": set,
|
|
|
- "$pull": map[string]interface{}{"a_jpushid": rid},
|
|
|
- })
|
|
|
- //删除未登录的pushid
|
|
|
- jyutil.UnLoginPush.DeleteBuff(rid)
|
|
|
- }
|
|
|
- }()
|
|
|
- jy.JyAppCreateSession(db.Mgo, session, userid, 0, rw, true, config.Middleground, config.Config.AppPushServiceRpc, config.Config.Criticality)
|
|
|
- return createSign(userid, rid, "登录后", session)
|
|
|
+ userid := mongodb.BsonIdToSId(user["_id"])
|
|
|
+ old_rid, _ := user["s_jpushid"].(string)
|
|
|
+ old_oid, _ := user["s_opushid"].(string)
|
|
|
+ old_ponetype, _ := user["s_appponetype"].(string)
|
|
|
+ off := true
|
|
|
+ log.Println("多账号登录:", user)
|
|
|
+ go func() {
|
|
|
+ if !isNewUser {
|
|
|
+ if rd := config.Compatible.Select(userid, `{"i_unlimited":1}`); rd != nil && len(*rd) > 0 {
|
|
|
+ i_unlimited := common.IntAll((*rd)["i_unlimited"])
|
|
|
+ if i_unlimited > 0 {
|
|
|
+ off = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.Println("publicapply:", old_rid, "---", old_oid, "---", rid, "---", off)
|
|
|
+ //同一账号在不同设备登录,极光id不一样,给之前的设备推送自定义的下线消息,离线消息保持10天
|
|
|
+ if old_rid != "" && old_rid != rid && off && rid != "" {
|
|
|
+ db.Mgo.UpdateById("user", userid, map[string]interface{}{
|
|
|
+ "$addToSet": map[string]interface{}{"a_jpushid": old_rid},
|
|
|
+ })
|
|
|
+ //
|
|
|
+ log.Println(userid, phoneType, rid, oid, "踢人下线", old_ponetype, old_rid, old_oid)
|
|
|
+ qrpc.AppPush(config.Config.AppPushServiceRpc, map[string]interface{}{
|
|
|
+ "type": "signOut",
|
|
|
+ "descript": kickedTip,
|
|
|
+ "jgPushId": old_rid,
|
|
|
+ "otherPushId": old_oid,
|
|
|
+ "phoneType": old_ponetype,
|
|
|
+ "userId": userid,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if channel != "" && deviceId != "" {
|
|
|
+ //更新用户最后一次登录渠道和设备信息
|
|
|
+ if db.Mgo.Count("jyapp_channel", map[string]interface{}{"s_userid": userid, "s_type": "lastLogin"}) > 0 {
|
|
|
+ update := map[string]interface{}{"i_cometime": time.Now().Unix(), "s_channel": channel}
|
|
|
+ db.Mgo.Update("jyapp_channel", map[string]interface{}{"s_userid": userid, "s_type": "lastLogin"},
|
|
|
+ map[string]interface{}{"$set": update}, false, true)
|
|
|
+ } else {
|
|
|
+ db.Mgo.Save("jyapp_channel", map[string]interface{}{
|
|
|
+ "s_deviceId": deviceId,
|
|
|
+ "s_type": "lastLogin",
|
|
|
+ "i_cometime": time.Now().Unix(),
|
|
|
+ "s_channel": channel,
|
|
|
+ "s_userid": userid,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if channel != "" && deviceId != "" {
|
|
|
+ //记录新用户注册渠道来源
|
|
|
+ db.Mgo.Save("jyapp_channel", map[string]interface{}{
|
|
|
+ "s_deviceId": deviceId,
|
|
|
+ "s_type": "regist",
|
|
|
+ "i_cometime": time.Now().Unix(),
|
|
|
+ "s_channel": channel,
|
|
|
+ "s_userid": userid,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if rid != "" {
|
|
|
+ db.Mgo.Update("user", map[string]interface{}{
|
|
|
+ "i_appid": 2,
|
|
|
+ "s_jpushid": rid,
|
|
|
+ }, map[string]interface{}{
|
|
|
+ "$unset": map[string]interface{}{
|
|
|
+ "s_jpushid": "",
|
|
|
+ "s_opushid": "",
|
|
|
+ },
|
|
|
+ }, false, true)
|
|
|
+ set := map[string]interface{}{
|
|
|
+ "s_jpushid": rid,
|
|
|
+ "s_opushid": oid,
|
|
|
+ "s_appponetype": phoneType,
|
|
|
+ }
|
|
|
+ if o_jy, ok := user["o_jy"].(map[string]interface{}); ok && o_jy != nil && o_jy["i_apppush"] == nil {
|
|
|
+ set["o_jy.i_apppush"] = 1
|
|
|
+ }
|
|
|
+ db.Mgo.UpdateById("user", userid, map[string]interface{}{
|
|
|
+ "$set": set,
|
|
|
+ "$pull": map[string]interface{}{"a_jpushid": rid},
|
|
|
+ })
|
|
|
+ //删除未登录的pushid
|
|
|
+ jyutil.UnLoginPush.DeleteBuff(rid)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ jy.JyAppCreateSession(db.Mgo, session, userid, 0, rw, true, config.Middleground, config.Config.AppPushServiceRpc, config.Config.Criticality)
|
|
|
+ return createSign(userid, rid, "登录后", session)
|
|
|
}
|
|
|
|
|
|
// UserSign 签名
|
|
|
type UserSign struct {
|
|
|
- CreateTime int64 `json:"createtime"`
|
|
|
- OpenId string `json:"openid"`
|
|
|
- UserId string `json:"userid"`
|
|
|
- Rid string `json:"rid"`
|
|
|
- Sign string `json:"sign"`
|
|
|
- Type int `json:"type"`
|
|
|
+ CreateTime int64 `json:"createtime"`
|
|
|
+ OpenId string `json:"openid"`
|
|
|
+ UserId string `json:"userid"`
|
|
|
+ Rid string `json:"rid"`
|
|
|
+ Sign string `json:"sign"`
|
|
|
+ Type int `json:"type"`
|
|
|
}
|
|
|
|
|
|
// 生成签名,返回手机端
|
|
|
func createSign(userid, rid, signType string, session *httpsession.Session) string {
|
|
|
- u := &UserSign{
|
|
|
- UserId: userid,
|
|
|
- CreateTime: time.Now().Unix(),
|
|
|
- Rid: rid,
|
|
|
- }
|
|
|
- u.Sign, _ = getSign(u)
|
|
|
- b, err := json.Marshal(u)
|
|
|
- if err != nil {
|
|
|
- log.Println(err)
|
|
|
- }
|
|
|
- sign := string(b)
|
|
|
- log.Println(signType, "生成签名加密前:", sign)
|
|
|
- sign = encrypt.SE.EncodeString(sign)
|
|
|
- sign = strings.Replace(sign, "+", "%2B", -1)
|
|
|
- log.Println(signType, "生成签名加密后:", sign)
|
|
|
- return sign
|
|
|
+ u := &UserSign{
|
|
|
+ UserId: userid,
|
|
|
+ CreateTime: time.Now().Unix(),
|
|
|
+ Rid: rid,
|
|
|
+ }
|
|
|
+ u.Sign, _ = getSign(u)
|
|
|
+ b, err := json.Marshal(u)
|
|
|
+ if err != nil {
|
|
|
+ log.Println(err)
|
|
|
+ }
|
|
|
+ sign := string(b)
|
|
|
+ log.Println(signType, "生成签名加密前:", sign)
|
|
|
+ sign = encrypt.SE.EncodeString(sign)
|
|
|
+ sign = strings.Replace(sign, "+", "%2B", -1)
|
|
|
+ log.Println(signType, "生成签名加密后:", sign)
|
|
|
+ return sign
|
|
|
}
|
|
|
func getSign(u *UserSign) (string, string) {
|
|
|
- newSign := common.GetMd5String(fmt.Sprintf("createtime=%d&userid=%s&rid=%s&type=%d", u.CreateTime, u.UserId, u.Rid, u.Type))
|
|
|
- oldSign := common.GetMd5String(fmt.Sprintf("createtime=%d&openid=%s&rid=%s&type=%d", u.CreateTime, u.OpenId, u.Rid, u.Type))
|
|
|
- return newSign, oldSign
|
|
|
+ newSign := common.GetMd5String(fmt.Sprintf("createtime=%d&userid=%s&rid=%s&type=%d", u.CreateTime, u.UserId, u.Rid, u.Type))
|
|
|
+ oldSign := common.GetMd5String(fmt.Sprintf("createtime=%d&openid=%s&rid=%s&type=%d", u.CreateTime, u.OpenId, u.Rid, u.Type))
|
|
|
+ return newSign, oldSign
|
|
|
}
|
|
|
|
|
|
// 保存日志
|
|
|
func (o OneClickInfo) saveLog(userId string, logType string) {
|
|
|
- q := map[string]interface{}{
|
|
|
- "s_user_id": userId,
|
|
|
- }
|
|
|
- u := map[string]interface{}{
|
|
|
- "$set": map[string]interface{}{
|
|
|
- logType: map[string]interface{}{
|
|
|
- "accessToken": o.AccessToken,
|
|
|
- "outId": o.OutId,
|
|
|
- "spToken": o.SpToken,
|
|
|
- "UA": o.UA,
|
|
|
- "requestId": o.RequestId,
|
|
|
- "vender": o.Vender,
|
|
|
- "createTime": time.Now().Unix(),
|
|
|
- },
|
|
|
- },
|
|
|
- }
|
|
|
- db.Mgo.Update("oneclick_log", q, u, true, false)
|
|
|
+ q := map[string]interface{}{
|
|
|
+ "s_user_id": userId,
|
|
|
+ }
|
|
|
+ u := map[string]interface{}{
|
|
|
+ "$set": map[string]interface{}{
|
|
|
+ logType: map[string]interface{}{
|
|
|
+ "accessToken": o.AccessToken,
|
|
|
+ "outId": o.OutId,
|
|
|
+ "spToken": o.SpToken,
|
|
|
+ "UA": o.UA,
|
|
|
+ "requestId": o.RequestId,
|
|
|
+ "vender": o.Vender,
|
|
|
+ "createTime": time.Now().Unix(),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ db.Mgo.Update("oneclick_log", q, u, true, false)
|
|
|
}
|