'use strict'; const Controller = require('egg').Controller; class AppletapiController extends Controller { async get_openid({ code }) { const token = await this.get_accessToken(); const url = `https://api.weixin.qq.com/wxa/getpluginopenpid?access_token=${token}`; const openid = await this.ctx.curl({ model: 'post', url, data: { code }, }); return openid; } async get_phone({ code }) { const token = await this.get_accessToken(); const url = `https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=${token}`; const data = await this.ctx.curl({ model: 'post', url, data: { code }, }); return data; } // 获取access_token async get_accessToken() { const { appid, appsecret } = this.app.config.wxconfig; const to_uri = `https://api.weixin.qq.com/cgi-bin/token?appid=${appid}&secret=${appsecret}&grant_type=client_credential`; const { access_token } = await this.ctx.curl(to_uri); return access_token; } } module.exports = AppletapiController;