Merge remote-tracking branch 'upstream/master'

pull/280969/MERGE^2
PPPSCN 2017-05-06 23:05:32 +08:00
commit 77ce4eedaf
6 changed files with 40 additions and 25 deletions

View File

@ -213,7 +213,7 @@ CREATE TABLE `fa_configvalue` (
-- Records of `fa_configvalue` -- Records of `fa_configvalue`
-- ---------------------------- -- ----------------------------
BEGIN; BEGIN;
INSERT INTO `fa_configvalue` VALUES ('wechat', '微信菜单', '{\"menu\":[{\"name\":\"极速后台\",\"sub_button\":[{\"name\":\"官网\",\"type\":\"view\",\"url\":\"http:\\/\\/www.fastadmin.net\"},{\"name\":\"演示站\",\"type\":\"view\",\"url\":\"http:\\/\\/demo.fastadmin.net\"}]},{\"name\":\"联系客\",\"type\":\"click\",\"key\":\"58cb852984970\"},{\"name\":\"关于我们\",\"type\":\"click\",\"key\":\"58bf944aa0777\"}],\"config\":[{\"id\":\"default.subscribe.message\",\"name\":\"关注后自动推送内容\",\"value\":\"欢迎关注我们!\"},{\"id\":\"cccdddd\",\"name\":\"dfsdffdsfdsdfsdfs\",\"value\":\"fsfsfsdfsdfdsfdsgggg\"}]}', '0', '1492186828', '5', 'normal'); INSERT INTO `fa_configvalue` VALUES ('wechat', '微信菜单', '{\"menu\":[{\"name\":\"极速后台\",\"sub_button\":[{\"name\":\"官网\",\"type\":\"view\",\"url\":\"http:\\/\\/www.fastadmin.net\"},{\"name\":\"演示站\",\"type\":\"view\",\"url\":\"http:\\/\\/demo.fastadmin.net\"}]},{\"name\":\"联系客\",\"type\":\"click\",\"key\":\"58cb852984970\"},{\"name\":\"关于我们\",\"type\":\"click\",\"key\":\"58bf944aa0777\"}],\"config\":[{\"id\":\"default.subscribe.message\",\"name\":\"关注后自动推送内容\",\"value\":\"欢迎关注我们!\"},{\"id\":\"cccdddd\",\"name\":\"dfsdffdsfdsdfsdfs\",\"value\":\"fsfsfsdfsdfdsfdsgggg\"}]}', '0', '1493986907', '5', 'normal');
COMMIT; COMMIT;
-- ---------------------------- -- ----------------------------
@ -373,7 +373,14 @@ CREATE TABLE `fa_wechat_autoreply` (
`updatetime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间', `updatetime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',
`status` varchar(30) NOT NULL DEFAULT '' COMMENT '状态', `status` varchar(30) NOT NULL DEFAULT '' COMMENT '状态',
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='微信自动回复表'; ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='微信自动回复表';
-- ----------------------------
-- Records of `fa_wechat_autoreply`
-- ----------------------------
BEGIN;
INSERT INTO `fa_wechat_autoreply` VALUES ('1', '输入hello', 'hello', '58c7d908c4570', '123', '1493366855', '1493366855', 'normal'), ('2', '输入你好', '你好', '58fdfaa9e1965', 'sad', '1493704976', '1493704976', 'normal');
COMMIT;
-- ---------------------------- -- ----------------------------
-- Table structure for `fa_wechat_context` -- Table structure for `fa_wechat_context`
@ -415,7 +422,7 @@ CREATE TABLE `fa_wechat_response` (
-- Records of `fa_wechat_response` -- Records of `fa_wechat_response`
-- ---------------------------- -- ----------------------------
BEGIN; BEGIN;
INSERT INTO `fa_wechat_response` VALUES ('1', '签到送积分', '58adaf7876aab', 'app', '{\"app\":\"signin\"}', '', '1487777656', '0', 'normal'), ('2', '关于我们', '58bf944aa0777', 'app', '{\"app\":\"article\",\"id\":\"1\"}', '', '1488950346', '0', 'normal'), ('3', '测试我们', '58c7d908c4570', 'text', '{\"content\":\"\\u8fd4\\u56de\\u6210\\u529f\\u5566\\uff01\"}', '测试我们', '1489492232', '0', 'normal'), ('4', '联系客服', '58cb852984970', 'app', '{\"app\":\"service\"}', '', '1489732905', '0', 'normal'); INSERT INTO `fa_wechat_response` VALUES ('1', '签到送积分', '58adaf7876aab', 'app', '{\"app\":\"signin\"}', '', '1487777656', '1487777656', 'normal'), ('2', '关于我们', '58bf944aa0777', 'app', '{\"app\":\"page\",\"id\":\"1\"}', '', '1488950346', '1488950346', 'normal'), ('3', '自动回复1', '58c7d908c4570', 'text', '{\"content\":\"world\"}', '', '1489492232', '1489492232', 'normal'), ('4', '联系客服', '58cb852984970', 'app', '{\"app\":\"service\"}', '', '1489732905', '1489732905', 'normal'), ('5', '自动回复2', '58fdfaa9e1965', 'text', '{\"content\":\"我是FastAdmin!\"}', '', '1493039785', '1493039785', 'normal');
COMMIT; COMMIT;
SET FOREIGN_KEY_CHECKS = 1; SET FOREIGN_KEY_CHECKS = 1;

View File

@ -64,7 +64,7 @@ class Menu extends Backend
public function sync($ids = NULL) public function sync($ids = NULL)
{ {
$this->code = -1; $this->code = -1;
$app = new Application(Config::get('wechat')->toArray()); $app = new Application(Config::get('wechat'));
try try
{ {

View File

@ -74,7 +74,7 @@ if (!function_exists('configvalue'))
*/ */
function configvalue($id) function configvalue($id)
{ {
$data = Configvalue::get('wechat'); $data = Configvalue::get($id);
return $data ? $data->content : null; return $data ? $data->content : null;
} }

View File

@ -3,11 +3,12 @@
namespace app\index\controller; namespace app\index\controller;
use app\common\controller\Frontend; use app\common\controller\Frontend;
use app\common\model\WechatAutoreply;
use app\common\model\WechatContext; use app\common\model\WechatContext;
use app\common\model\WechatResponse; use app\common\model\WechatResponse;
use EasyWeChat\Foundation\Application;
use EasyWeChat\Payment\Order; use EasyWeChat\Payment\Order;
use fast\service\Wechat as WechatService; use fast\service\Wechat as WechatService;
use fast\third\Application;
use think\Config; use think\Config;
use think\Log; use think\Log;
@ -22,7 +23,7 @@ class Wechat extends Frontend
public function _initialize() public function _initialize()
{ {
parent::_initialize(); parent::_initialize();
$this->app = new Application(Config::getSecret('wechat')->toArray()); $this->app = new Application(Config::get('wechat'));
} }
/** /**
@ -68,11 +69,11 @@ class Wechat extends Frontend
break; break;
} }
$response = $WechatResponse->where(["eventkey" => $eventkey, 'status' => FA_STATUS_NORMAL])->get(); $response = $WechatResponse->where(["eventkey" => $eventkey, 'status' => 'normal'])->find();
if ($response) if ($response)
{ {
$content = (array) json_decode($response['content'], TRUE); $content = (array) json_decode($response['content'], TRUE);
$context = $WechatContext->where(['openid' => $openid])->get(); $context = $WechatContext->where(['openid' => $openid])->find();
$data = ['eventkey' => $eventkey, 'command' => '', 'refreshtime' => time(), 'openid' => $openid]; $data = ['eventkey' => $eventkey, 'command' => '', 'refreshtime' => time(), 'openid' => $openid];
if ($context) if ($context)
{ {
@ -81,7 +82,7 @@ class Wechat extends Frontend
} }
else else
{ {
$id = $WechatContext->data($data)->insert(); $id = $WechatContext->data($data)->save();
$data['id'] = $id; $data['id'] = $id;
} }
$result = $WechatService->response($this, $openid, $content, $data); $result = $WechatService->response($this, $openid, $content, $data);
@ -99,10 +100,10 @@ class Wechat extends Frontend
case 'link': //链接消息 case 'link': //链接消息
default: //其它消息 default: //其它消息
//上下文事件处理 //上下文事件处理
$context = $WechatContext->where([['openid', $openid], ['refreshtime', '>=', time() - 1800]])->get(); $context = $WechatContext->where(['openid' => ['=', $openid], 'refreshtime' => ['>=', time() - 1800]])->find();
if ($context && $context['eventkey']) if ($context && $context['eventkey'])
{ {
$response = $WechatResponse->where(['eventkey' => $context['eventkey'], 'status' => FA_STATUS_NORMAL])->get(); $response = $WechatResponse->where(['eventkey' => $context['eventkey'], 'status' => 'normal'])->find();
if ($response) if ($response)
{ {
$WechatContext->data(array('refreshtime' => time()))->where('id', $context['id'])->update(); $WechatContext->data(array('refreshtime' => time()))->where('id', $context['id'])->update();
@ -117,15 +118,15 @@ class Wechat extends Frontend
//自动回复处理 //自动回复处理
if ($message->MsgType == 'text') if ($message->MsgType == 'text')
{ {
$wechat_autoreply = new Orm('wechat_autoreply'); $wechat_autoreply = new WechatAutoreply();
$autoreply = $wechat_autoreply->where(['text' => $message->Content, 'status' => FA_STATUS_NORMAL])->get(); $autoreply = $wechat_autoreply->where(['text' => $message->Content, 'status' => 'normal'])->find();
if ($autoreply) if ($autoreply)
{ {
$response = $WechatResponse->where(["eventkey" => $autoreply['eventkey'], 'status' => FA_STATUS_NORMAL])->get(); $response = $WechatResponse->where(["eventkey" => $autoreply['eventkey'], 'status' => 'normal'])->find();
if ($response) if ($response)
{ {
$content = (array) json_decode($response['content'], TRUE); $content = (array) json_decode($response['content'], TRUE);
$context = $WechatContext->where(['openid' => $openid])->get(); $context = $WechatContext->where(['openid' => $openid])->find();
$result = $WechatService->response($this, $openid, $content, $context); $result = $WechatService->response($this, $openid, $content, $context);
if ($result) if ($result)
{ {

View File

@ -9,6 +9,7 @@ use app\common\model\UserThird;
use EasyWeChat\Message\News; use EasyWeChat\Message\News;
use EasyWeChat\Message\Transfer; use EasyWeChat\Message\Transfer;
use fast\Date; use fast\Date;
use think\Config;
/** /**
* Wechat服务类 * Wechat服务类
@ -62,7 +63,6 @@ class Wechat
// 微信输入交互内容指令 // 微信输入交互内容指令
public function command($obj, $openid, $content, $context) public function command($obj, $openid, $content, $context)
{ {
$content = [];
$response = FALSE; $response = FALSE;
if (isset($content['app'])) if (isset($content['app']))
{ {
@ -131,7 +131,7 @@ class Wechat
// 微信点击菜单event指令 // 微信点击菜单event指令
public function response($obj, $openid, $content, $context) public function response($obj, $openid, $content, $context)
{ {
$content = []; $upload = Config::get('upload');
$response = FALSE; $response = FALSE;
if (isset($content['app'])) if (isset($content['app']))
{ {
@ -176,8 +176,8 @@ class Wechat
{ {
$news = new News(); $news = new News();
$news->title = $pageinfo['title']; $news->title = $pageinfo['title'];
$news->url = $pageinfo['outlink'] ? $pageinfo['outlink'] : url('page/show/' . $pageinfo['id'], 1); $news->url = $pageinfo['url'] ? $pageinfo['url'] : url('index/page/show', ['id' => $pageinfo['id']], true, true);
$news->image = cdn($pageinfo['image']); $news->image = $upload['cdnurl'] . $pageinfo['image'];
$news->description = $pageinfo['description']; $news->description = $pageinfo['description'];
$response[] = $news; $response[] = $news;
} }
@ -190,8 +190,8 @@ class Wechat
{ {
$news = new News(); $news = new News();
$news->title = $pageinfo['title']; $news->title = $pageinfo['title'];
$news->url = $pageinfo['outlink'] ? $pageinfo['outlink'] : url('page/show/' . $pageinfo['id'], 1); $news->url = $pageinfo['url'] ? $pageinfo['url'] : url('index/page/show', ['id' => $pageinfo['id']], true, true);
$news->image = cdn($pageinfo['image']); $news->image = $upload['cdnurl'] . $pageinfo['image'];
$news->description = $pageinfo['description']; $news->description = $pageinfo['description'];
return $news; return $news;
} }

View File

@ -54,11 +54,18 @@ define(['jquery', 'bootstrap', 'backend', 'addtabs', 'adminlte', 'validator'], f
dataType: 'json', dataType: 'json',
cache: false, cache: false,
success: function (ret) { success: function (ret) {
if (ret.code === 1) { if (ret.hasOwnProperty("code")) {
Backend.api.toastr.success(__('Wipe cache completed')); var msg = ret.hasOwnProperty("msg") && ret.msg != "" ? ret.msg : "";
if (ret.code === 1) {
Toastr.success(msg ? msg : __('Wipe cache completed'));
} else {
Toastr.error(msg ? msg : __('Wipe cache failed'));
}
} else { } else {
Backend.api.toastr.error(__('Wipe cache failed')); Toastr.error(__('Unknown data format'));
} }
}, error: function () {
Toastr.error(__('Network error'));
} }
}); });
}); });