作者 魏强

微信服务接口

  1 +<?php
  2 +// +----------------------------------------------------------------------
  3 +// | bronet [ 以客户为中心 以奋斗者为本 ]
  4 +// +----------------------------------------------------------------------
  5 +// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
  6 +// +----------------------------------------------------------------------
  7 +// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8 +// +----------------------------------------------------------------------
  9 +// | Author: Powerless < wzxaini9@gmail.com>
  10 +// +----------------------------------------------------------------------
  11 +namespace app\portal\controller;
  12 +
  13 +
  14 +use EasyWeChat\Foundation\Application;
  15 +
  16 +class WechatController
  17 +{
  18 + public function index()
  19 + {
  20 + $app=new Application(config('wechat_config'));
  21 + $server = $app->server;
  22 +
  23 + $server->setMessageHandler(function ($message) {
  24 + switch ($message->MsgType) {
  25 + case 'event':
  26 + switch ($message->Event) {
  27 + case 'subscribe':
  28 + return '欢迎关注';
  29 + break;
  30 + case 'CLICK':
  31 + return 'CLICKCLICK';
  32 + break;
  33 + default:
  34 + return '收到event消息111'.$message->Event;
  35 + break;
  36 + }
  37 + break;
  38 + case 'text':
  39 + return '收到文字消息';
  40 + break;
  41 + default:
  42 + return '收到其它消息';
  43 + break;
  44 + }
  45 + });
  46 +
  47 + $response = $server->serve();
  48 +
  49 + $response->send();
  50 + }
  51 +
  52 +}
  1 +<?php
  2 +// +----------------------------------------------------------------------
  3 +// | bronet [ 以客户为中心 以奋斗者为本 ]
  4 +// +----------------------------------------------------------------------
  5 +// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
  6 +// +----------------------------------------------------------------------
  7 +// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8 +// +----------------------------------------------------------------------
  9 +// | Author: Powerless < wzxaini9@gmail.com>
  10 +// +----------------------------------------------------------------------
  11 +namespace app\portal\controller;
  12 +
  13 +
  14 +use EasyWeChat\Foundation\Application;
  15 +
  16 +/**
  17 + * 微信服务器接口
  18 + * Class WechatController
  19 + * @package app\portal\controller
  20 + */
  21 +class WechatController
  22 +{
  23 +
  24 + public function index(){
  25 + $app=new Application(config('wechat_config'));
  26 + $server = $app->server;
  27 +
  28 + $server->setMessageHandler(function ($message) {
  29 + switch ($message->MsgType) {
  30 + case 'event':
  31 + switch ($message->Event) {
  32 + case 'subscribe':
  33 + return '欢迎关注';
  34 + break;
  35 + case 'CLICK':
  36 + $content = $message->EventKey; // 获取key
  37 + return '收到CLICK事件:'.$content;
  38 + break;
  39 + default:
  40 + return '收到event消息';
  41 + break;
  42 + }
  43 + break;
  44 + case 'text':
  45 + return '收到文字消息';
  46 + break;
  47 + default:
  48 + return '收到其它消息';
  49 + break;
  50 + }
  51 + });
  52 +
  53 + $response = $server->serve();
  54 +
  55 + $response->send();
  56 + }
  57 +
  58 +}