12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- 'use strict';
- const Controller = require('egg').Controller;
- class WXController extends Controller {
- async getAppidByCid() {
- const { ctx, service } = this;
- const query = ctx.query;
- const { cid } = query;
- const result = await service.wxConfigService.list({ cid });
- if (result.length === 1) {
- ctx.success(result[0]);
- } else {
- ctx.error('appid(' + cid + ') is error ');
- }
- }
- async oauth() {
- const { ctx, service } = this;
- const query = ctx.query;
- this.ctx.body = await service.wxService.oauth(query);
- }
- async getAppletOpenId() {
- const { ctx, service } = this;
- const query = ctx.query;
- this.ctx.body = await service.wxService.getAppletOpenId(query);
- }
- async toWechat() {
- const message = this.ctx.req.body;
- if (message) {
- const MsgType = message.MsgType;
- let reply;
- if (MsgType === 'event') {
- reply = await this.service.wxService.handleEvent(message);
- } else {
- reply = await this.service.wxService.handleMsg(message);
- }
- if (reply) {
- const result = await this.service.wxService.replyMsg(message, reply);
- this.ctx.body = result;
- return true;
- }
- }
- this.ctx.body = 'success';
- }
- async createMenu() {
- const config = this.ctx.app.config.wechat_config;
- this.ctx.body = await this.service.wxService.createMenu(config.appId);
- }
- async getUserInfo() {
- const { ctx, service } = this;
- const query = ctx.query;
- const { openid } = query;
- this.ctx.body = await service.wxService.getUserInfo(openid);
- }
- async getSign() {
- const { ctx, service } = this;
- const query = ctx.query;
- this.ctx.body = await service.wxService.getSign(query);
- }
- }
- module.exports = WXController;
|