|
@@ -20,16 +20,26 @@ class WxpayService extends CrudService {
|
|
async toAuth({ code, id }) {
|
|
async toAuth({ code, id }) {
|
|
const token = await this.redis.get(id);
|
|
const token = await this.redis.get(id);
|
|
if (token) return;
|
|
if (token) return;
|
|
- const url = `https://api.weixin.qq.com/sns/jscode2session?appid=${this.appInfo.id}&secret=${this.appInfo.secret}&js_code=${code}&grant_type=authorization_code`;
|
|
|
|
|
|
+ let url;
|
|
|
|
+ try {
|
|
|
|
+ url = `https://api.weixin.qq.com/sns/jscode2session?appid=${this.appInfo.id}&secret=${this.appInfo.secret}&js_code=${code}&grant_type=authorization_code`;
|
|
|
|
+ console.log(`url=>${url}`);
|
|
|
|
+ } catch (error) {
|
|
|
|
+ throw new BusinessError(ErrorCode.SERVICE_FAULT, 'url拼接出错');
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ const res = await this.ctx.curl(url, {
|
|
|
|
+ method: 'get',
|
|
|
|
+ dataType: 'json',
|
|
|
|
+ });
|
|
|
|
+ console.log(`res=>${res}`);
|
|
|
|
+ const info = JSON.stringify(res.data);
|
|
|
|
+ await this.redis.set(id, info, 'EX', 3600);
|
|
|
|
+ } catch (error) {
|
|
|
|
+ throw new BusinessError(ErrorCode.SERVICE_FAULT, '请求出错');
|
|
|
|
+ }
|
|
// const url = appInfo => `https://api.weixin.qq.com/sns/jscode2session?appid=${appInfo.id}&secret=${appInfo.secret}&js_code=${code}&grant_type=authorization_code`;
|
|
// const url = appInfo => `https://api.weixin.qq.com/sns/jscode2session?appid=${appInfo.id}&secret=${appInfo.secret}&js_code=${code}&grant_type=authorization_code`;
|
|
- console.log(`url=>${url}`);
|
|
|
|
- const res = await this.ctx.curl(url, {
|
|
|
|
- method: 'get',
|
|
|
|
- dataType: 'json',
|
|
|
|
- });
|
|
|
|
- console.log(`res=>${res}`);
|
|
|
|
- const info = JSON.stringify(res.data);
|
|
|
|
- await this.redis.set(id, info, 'EX', 3600);
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
async cash({ id, name, money }) {
|
|
async cash({ id, name, money }) {
|