processor.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. /*=============================================================================
  3. # FileName: processor.php
  4. # Desc:
  5. # Author: Yunzhong - http://www.yunzshop.com
  6. # Email: 913768135@qq.com
  7. # HomePage: http://www.yunzshop.com
  8. # Version: 0.0.1
  9. # LastChange: 2016-02-05 02:08:51
  10. # History:
  11. =============================================================================*/
  12. if (!defined('IN_IA')) {
  13. exit('Access Denied');
  14. }
  15. define('IS_API', true);
  16. class Yun_shopModuleProcessor extends WeModuleProcessor
  17. {
  18. public function __construct()
  19. {
  20. parent::__construct();
  21. }
  22. /**
  23. * 预定义的操作, 构造返回文本消息结构
  24. * @param string $content 回复的消息内容
  25. * @return array 返回统一响应消息结构
  26. */
  27. public function text($content)
  28. {
  29. return parent::respText($content);
  30. }
  31. /**
  32. * 预定义的操作, 构造返回转接多客服结构
  33. * @return array 返回的消息数组结构
  34. */
  35. public function custom(array $message = array())
  36. {
  37. return parent::respCustom($message);
  38. }
  39. /**
  40. * 预定义的操作, 构造返回图像消息结构
  41. * @param string $mid 回复的图像资源ID
  42. * @return array 返回的消息数组结构
  43. */
  44. public function image($mid)
  45. {
  46. return parent::respImage($mid);
  47. }
  48. /**
  49. * 预定义的操作, 构造返回音乐消息结构
  50. * @param string $music 回复的音乐定义(包含元素
  51. * title - string: 音乐标题,
  52. * description - string: 音乐描述,
  53. * musicurl - string: 音乐地址,
  54. * hqhqmusicurl - string: 高品质音乐地址,
  55. * thumb - string: 音乐封面资源ID)
  56. * @return array 返回的消息数组结构
  57. */
  58. public function music(array $music)
  59. {
  60. return parent::respMusic($music);
  61. }
  62. /**
  63. * 预定义的操作, 构造返回图文消息结构, 一条图文消息不能超过 10 条内容
  64. * @param array $news 回复的图文定义,定义为元素集合
  65. * array(
  66. 'title' => '', // string: 新闻标题
  67. 'picurl' => '', // string: 图片链接
  68. 'url' => '', // string: 原文链接
  69. 'description' => '' //string: 新闻描述
  70. );
  71. * @return array 返回的消息数组结构
  72. */
  73. public function news(array $news)
  74. {
  75. return parent::respNews($news);
  76. }
  77. /**
  78. * 预定义的操作, 构造返回视频消息结构
  79. * @param array $video 回复的视频定义(包含两个元素
  80. * video - string: 视频资源ID,
  81. * thumb - string: 视频缩略图资源ID)
  82. * @return array 返回的消息数组结构
  83. */
  84. public function video(array $video)
  85. {
  86. return parent::respVideo($video);
  87. }
  88. /**
  89. * 预定义的操作, 构造返回声音消息结构
  90. * @param string $mid 回复的音频资源ID
  91. * @return array 返回的消息数组结构
  92. */
  93. public function voice($mid)
  94. {
  95. return parent::respVoice($mid);
  96. }
  97. public function respond()
  98. {
  99. // \Log::debug('------微擎微信公众号消息-----', json_encode($this->rule));
  100. // $user_data = array(
  101. // 'participation' => json_encode($this),
  102. // 'set_private_send_msg' => $this->message['msgtype'],
  103. // );
  104. // pdo_update('yz_forwarding_treasure', $user_data, array('id' => 3));
  105. //因为任意图片无法匹配到规则 所以图片消息单独处理 start
  106. if($this->message['msgtype'] == 'image'){
  107. //因为目前只有转发宝功能需要 所以直接查询转发宝的配置文件 如果存在直接进入事件监听
  108. $setting = pdo_fetch('select * from ' . tablename('yz_setting') . ' where `group`=:groupw and `key`=:keyw limit 1', array(
  109. ':groupw' => 'plugin',
  110. ':keyw'=>'forwarding-treasure'
  111. ));
  112. if(empty($setting)){
  113. return false;
  114. }
  115. // $setting = serialize($setting['value']);
  116. // $user_data = array(
  117. // 'area_data' => json_encode($setting),
  118. // );
  119. // pdo_update('yz_forwarding_treasure', $user_data, array('id' => 3));
  120. $plugin = 'forwarding-treasure';
  121. //引入laravel
  122. require_once __DIR__.'/bootstrap/autoload.php';
  123. $app = require_once __DIR__.'/bootstrap/app.php';
  124. $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
  125. $kernel->handle(
  126. $request = \app\framework\Http\Request::capture()
  127. );
  128. //微信接口事件
  129. $response = '';
  130. event(new \app\common\events\WechatProcessor($this,$plugin,$response));
  131. return $response;
  132. }
  133. //end 以下为以前的代码
  134. $rule = pdo_fetch('select * from ' . tablename('rule') . ' where id=:id limit 1', array(
  135. ':id' => $this->rule
  136. ));
  137. if (empty($rule)) {
  138. return false;
  139. }
  140. $names = explode(':', $rule['name']);
  141. $plugin = isset($names[1]) ? $names[1] : '';
  142. if (!empty($plugin)) {
  143. //引入laravel
  144. require_once __DIR__.'/bootstrap/autoload.php';
  145. $app = require_once __DIR__.'/bootstrap/app.php';
  146. $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
  147. $kernel->handle(
  148. $request = \app\framework\Http\Request::capture()
  149. );
  150. //扫海报事件队列
  151. /*
  152. $msg = $this->message;
  153. $msgType = strtolower($msg['msgtype']);
  154. $msgEvent = strtolower($msg['event']);
  155. if ($msgType == 'event' && ($msgEvent == 'scan' || $msgEvent == 'subscribe')) {
  156. $job = (new \app\Jobs\scanPostConcernQueueJob(YunShop::app()->uniacid, $this))
  157. ->delay(\Carbon\Carbon::now()->addMinutes(5));
  158. dispatch($job);
  159. \Log::debug('------poster queue job start-----');
  160. }
  161. */
  162. //微信接口事件
  163. $response = '';
  164. event(new \app\common\events\WechatProcessor($this,$plugin,$response));
  165. return $response;
  166. }
  167. return false;
  168. }
  169. }