|
|
|
@@ -7,8 +7,8 @@ import ( |
|
|
|
"code.gitea.io/gitea/modules/redis/redis_client" |
|
|
|
"code.gitea.io/gitea/modules/redis/redis_key" |
|
|
|
"code.gitea.io/gitea/modules/setting" |
|
|
|
"encoding/json" |
|
|
|
"errors" |
|
|
|
"fmt" |
|
|
|
gouuid "github.com/satori/go.uuid" |
|
|
|
"time" |
|
|
|
) |
|
|
|
@@ -42,37 +42,26 @@ func GetQRCode4Bind(ctx *context.Context) { |
|
|
|
|
|
|
|
// GetQRCode4Bind get QR code for wechat binding |
|
|
|
func GetBindStatus(ctx *context.Context) { |
|
|
|
//var status int |
|
|
|
//sceneStr := ctx.Query("sceneStr") |
|
|
|
//val, _ := redis_client.Get(redis_key.WechatBindingUserIdKey(sceneStr)) |
|
|
|
//if val == "" { |
|
|
|
// ctx.JSON(200, map[string]interface{}{ |
|
|
|
// "code": "9999", |
|
|
|
// "msg": "Get QR code failed", |
|
|
|
// "data": |
|
|
|
// //todo 继续完善查询接口,注意性能 |
|
|
|
// //todo 二维码重定向页面需要给一下 |
|
|
|
// //todo 微信推送Ng转发验证 |
|
|
|
// //todo 整体联调 |
|
|
|
// }) |
|
|
|
// return |
|
|
|
//} |
|
|
|
// |
|
|
|
//userId, _ := strconv.ParseInt(val, 10, 64) |
|
|
|
// |
|
|
|
//r, err := createQRCode4Bind(userId) |
|
|
|
//if err != nil { |
|
|
|
// ctx.JSON(200, map[string]interface{}{ |
|
|
|
// "code": "9999", |
|
|
|
// "msg": "Get QR code failed", |
|
|
|
// }) |
|
|
|
// return |
|
|
|
//} |
|
|
|
|
|
|
|
sceneStr := ctx.Query("sceneStr") |
|
|
|
val, _ := redis_client.Get(redis_key.WechatBindingUserIdKey(sceneStr)) |
|
|
|
if val == "" { |
|
|
|
ctx.JSON(200, map[string]interface{}{ |
|
|
|
"code": "00", |
|
|
|
"msg": "QR code expired", |
|
|
|
"data": map[string]interface{}{ |
|
|
|
"status": wechat.BIND_STATUS_EXPIRED, |
|
|
|
}, |
|
|
|
}) |
|
|
|
return |
|
|
|
} |
|
|
|
qrCache := new(wechat.QRCode4BindCache) |
|
|
|
json.Unmarshal([]byte(val), qrCache) |
|
|
|
ctx.JSON(200, map[string]interface{}{ |
|
|
|
"code": "00", |
|
|
|
"msg": "success", |
|
|
|
//"data": r, |
|
|
|
"data": map[string]interface{}{ |
|
|
|
"status": qrCache.Status, |
|
|
|
}, |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
@@ -83,7 +72,11 @@ func createQRCode4Bind(userId int64) (*QRCodeResponse, error) { |
|
|
|
return nil, errors.New("createQRCode4Bind failed") |
|
|
|
} |
|
|
|
|
|
|
|
isOk, err := redis_client.Setex(redis_key.WechatBindingUserIdKey(sceneStr), fmt.Sprint(userId), time.Duration(setting.WechatQRCodeExpireSeconds)*time.Second) |
|
|
|
jsonStr, _ := json.Marshal(&wechat.QRCode4BindCache{ |
|
|
|
UserId: userId, |
|
|
|
Status: wechat.BIND_STATUS_UNBIND, |
|
|
|
}) |
|
|
|
isOk, err := redis_client.Setex(redis_key.WechatBindingUserIdKey(sceneStr), string(jsonStr), time.Duration(setting.WechatQRCodeExpireSeconds)*time.Second) |
|
|
|
if err != nil { |
|
|
|
log.Error("createQRCode4Bind failed.e=%v", err) |
|
|
|
return nil, err |
|
|
|
|