|
|
|
@@ -18,28 +18,33 @@ const ( |
|
|
|
BIND_STATUS_EXPIRED = 9 |
|
|
|
) |
|
|
|
|
|
|
|
type WechatAccountUsedError struct { |
|
|
|
} |
|
|
|
const ( |
|
|
|
BIND_REPLY_SUCCESS = "启智账号认证微信成功" |
|
|
|
BIND_REPLY_WECHAT_ACCOUNT_USED = "认证失败,您的微信号已绑定其他启智账号" |
|
|
|
BIND_REPLY_OPENI_ACCOUNT_USED = "认证失败,您待认证的启智账号已绑定其他微信号" |
|
|
|
BIND_REPLY_FAILED_DEFAULT = "微信认证失败" |
|
|
|
) |
|
|
|
|
|
|
|
func (err WechatAccountUsedError) Error() string { |
|
|
|
return fmt.Sprint("wechat account has been used") |
|
|
|
type WechatBindError struct { |
|
|
|
Reply string |
|
|
|
} |
|
|
|
|
|
|
|
type OpenIAccountUsedError struct { |
|
|
|
func NewWechatBindError(reply string) WechatBindError { |
|
|
|
return WechatBindError{Reply: reply} |
|
|
|
} |
|
|
|
|
|
|
|
func (err OpenIAccountUsedError) Error() string { |
|
|
|
return fmt.Sprint("openI account has been used") |
|
|
|
func (err WechatBindError) Error() string { |
|
|
|
return fmt.Sprint("wechat bind error,reply=%s", err.Reply) |
|
|
|
} |
|
|
|
|
|
|
|
func BindWechat(userId int64, wechatOpenId string) error { |
|
|
|
if !IsWechatAccountAvailable(userId, wechatOpenId) { |
|
|
|
log.Error("bind wechat failed, because user use wrong wechat account to bind,userId=%d wechatOpenId=%s", userId, wechatOpenId) |
|
|
|
return WechatAccountUsedError{} |
|
|
|
return NewWechatBindError(BIND_REPLY_WECHAT_ACCOUNT_USED) |
|
|
|
} |
|
|
|
if !IsUserAvailableForWechatBind(userId, wechatOpenId) { |
|
|
|
log.Error("openI account has been used,userId=%d wechatOpenId=%s", userId, wechatOpenId) |
|
|
|
return OpenIAccountUsedError{} |
|
|
|
return NewWechatBindError(BIND_REPLY_OPENI_ACCOUNT_USED) |
|
|
|
} |
|
|
|
return models.BindWechatOpenId(userId, wechatOpenId) |
|
|
|
} |
|
|
|
|