Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

egg.js 的集成问题 #36

Open
whileLooper opened this issue Jan 5, 2018 · 4 comments
Open

egg.js 的集成问题 #36

whileLooper opened this issue Jan 5, 2018 · 4 comments

Comments

@whileLooper
Copy link

whileLooper commented Jan 5, 2018

'use strict';

const wechat = require('co-wechat');

module.exports = app => {
  class HomeController extends app.Controller { }

  // 因为 Egg 需要用类的形式来组织,而 wechat 是通过 middleware 方法来生成中间件
  HomeController.prototype.wechat = wechat({
    token: '',
    appid: '',
    encodingAESKey: ''
  }).middleware(async (message, ctx) => {
    // TODO
    var content = message.Content;
    var reply = '无法回复您的内容: ' + content;
    if (message.MsgType === 'event') {
      if (message.Event === 'subscribe') {
        if (message.EventKey) {
          //扫描二维码事件
          console.log('扫描二维码进入...');
        }

        reply = 'Thanks to subscribe. \r\n';
      } else if (message.Event === 'unsubscribe') {
        // 取消关注
        console.log('取消关注。。。');
        reply = '';
      } 
    } else if (message.MsgType === 'text') {


      // 用户输入文本选项
      switch (content) {
        case '1':
          reply = '您当前选项为 1。'
          break;

        case '2':
          reply = '您当前选项为 2。'
          break;

        case '3':
          reply = '您当前选项为 3。'
          break;

        default:
          break;
      }
      return reply;
    }

    await next();
  });

  return HomeController;
};

我用了微信公众平台接口调试工具进行调试,基础支持返回access_token,消息接口测试返回的是请求失败,手机上也是返回服务出现故障,刚刚上手egg.js,请问是哪里出现了问题?

重新修改了下代码

@JacksonTian
Copy link
Member

请按文档写。

@whileLooper
Copy link
Author

whileLooper commented Jan 22, 2018

需要填写appsecret在config里面吗? 还是之前就需要验证?
同样的代码我用ngrok + 微信测试号可以自动回复,但是部署到heroku后还是返回服务出现故障?想问下可能是什么原因?

@JacksonTian
Copy link
Member

上面的代码明显是写得不对的

@yanggee
Copy link

yanggee commented Oct 16, 2019

egg 的集成有问题啊,一直调试不通

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants