|
@@ -54,11 +54,18 @@ class WeixinController extends Controller {
|
|
|
await this.app.redis.set(key, val, 'EX', 600);
|
|
|
|
|
|
// TODO: 生成回调地址
|
|
|
+ // const { wxapi, authUrl = this.ctx.path } = this.app.config;
|
|
|
+ // const backUrl = encodeURI(
|
|
|
+ // `${this.app.config.baseUrl}${this.config.authUrl}?state=${state}`
|
|
|
+ // );
|
|
|
+ // const to_uri = `${wxapi.baseUrl}/api/auth?appid=${wxapi.appid}&response_type=code&redirect_uri=${backUrl}&connect_redirect=1#wechat`;
|
|
|
+ // console.log('url-->' + to_uri);
|
|
|
+ // this.ctx.redirect(to_uri);
|
|
|
const { wxapi, authUrl = this.ctx.path } = this.app.config;
|
|
|
- const backUrl = encodeURI(
|
|
|
- `${this.app.config.baseUrl}${this.config.authUrl}?state=${state}`
|
|
|
- );
|
|
|
- const to_uri = `${wxapi.baseUrl}/api/auth?appid=${wxapi.appid}&response_type=code&redirect_uri=${backUrl}&connect_redirect=1#wechat`;
|
|
|
+ const backUrl = encodeURI(`${this.app.config.baseUrl}${this.config.authUrl}?state=${state}`);
|
|
|
+ // const to_uri = `${wxapi.baseUrl}/api/auth?appid=${wxapi.appid}&response_type=code&redirect_uri=${backUrl}&connect_redirect=1#wechat`;
|
|
|
+ // const backUrl = encodeURI(`${this.app.config.baseUrl}${this.config.authUrl}/`);
|
|
|
+ const to_uri = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${wxapi.appid}&response_type=code&scope=snsapi_base&redirect_uri=${backUrl}&state=${state}&connect_redirect=1#wechat_redirect`;
|
|
|
console.log('url-->' + to_uri);
|
|
|
this.ctx.redirect(to_uri);
|
|
|
}
|
|
@@ -137,26 +144,33 @@ class WeixinController extends Controller {
|
|
|
assert(openid, 'openid不能为空');
|
|
|
if (openid) {
|
|
|
console.log('redirect_uri-->' + redirect_uri);
|
|
|
- let user = await this.ctx.service.user.findByOpenid(openid);
|
|
|
- user = JSON.parse(JSON.stringify(user));
|
|
|
+ const user = await this.ctx.service.user.findByOpenid(openid);
|
|
|
if (type === '0') {
|
|
|
// 通过openid取得用户信息
|
|
|
if (user) {
|
|
|
- const token = await this.ctx.service.login.createJwt(user);
|
|
|
- console.log(`token:${token}\n`);
|
|
|
+ const user_ = JSON.parse(JSON.stringify(user));
|
|
|
+ user_ = checkVip(user_);
|
|
|
+ const token = await this.ctx.service.login.createJwt(user_);
|
|
|
const to_uri = urljoin(redirect_uri, `?token=${token}`);
|
|
|
// TODO: 重定性页面
|
|
|
console.log('to_uri000-->' + to_uri);
|
|
|
this.ctx.redirect(to_uri);
|
|
|
} else {
|
|
|
console.log('rrr0000--->' + redirect_uri);
|
|
|
- const touri = `${this.app.config.baseUrl}/mobile/error`;
|
|
|
+ const touri = `${this.app.config.baseUrl}/platmobile/error`;
|
|
|
const to_uri = urljoin(touri, `?openid=${openid}`);
|
|
|
// TODO: 重定性页面
|
|
|
this.ctx.redirect(to_uri);
|
|
|
}
|
|
|
} else if (type === '1') {
|
|
|
- const user = await this.checkVip(user);
|
|
|
+ const to_uri = urljoin(
|
|
|
+ redirect_uri,
|
|
|
+ `?openid=${openid}&uid=${uid}&type=${type}&qrcode=${qrcode}`
|
|
|
+ );
|
|
|
+ // TODO: 重定性页面
|
|
|
+ console.log('1111---?' + to_uri);
|
|
|
+ this.ctx.redirect(to_uri);
|
|
|
+ } else if (type === '2') {
|
|
|
const to_uri = urljoin(
|
|
|
redirect_uri,
|
|
|
`?openid=${openid}&uid=${uid}&type=${type}&qrcode=${qrcode}`
|