12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- /**
- * OaReturnMsg.php UTF-8
- * 微信回复内容处理程序
- *
- * @date : 2018/9/27 14:40
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : chenbingling <cbl@huosdk.com>
- * @version : HuoMp 1.0
- */
- namespace huoMpMsg\controller;
- use huo\controller\wap\Option;
- use huolib\constant\CacheConst;
- use huolib\constant\OptionConst;
- use huolib\constant\WeiXinMenuConst;
- use huomp\model\weixin\MpConfModel;
- use huoMpMsg\model\MpMenuModel;
- use think\Cache;
- class OaReturnMsg {
- /**
- * 获取关注回复内容
- *
- * @param $mp_id
- *
- * @return string
- */
- public function getSubscribeMsg($mp_id) {
- $_conf_id = (new MpConfModel())->getIdByMpId($mp_id);
- if (empty($_conf_id)) {
- return '';
- }
- $_setting_name = OptionConst::WEIXIN_SUBSCRIBE_RETURN_MSG.$_conf_id;
- $_m = new Option();
- $_item = $_m->getOptionData($_setting_name, 1, true);
- if (!empty($_item['option_value'])) {
- $_item['option_value'] = json_decode($_item['option_value'], true);
- }
- if (!empty($_item['option_value']['text'])) {
- return $_item['option_value']['text'];
- }
- return '';
- }
- /**
- * 获取关键词自定义回复内容
- *
- * @param string $mp_id 公众号app_id
- * @param string $key 关键词
- * @param int $is_menu 是否菜单
- *
- * @return mixed|string
- */
- public function getKeyReturnMsg($mp_id, $key, $is_menu = WeiXinMenuConst::IS_MENU_1) {
- if (empty($key)) {
- return '';
- }
- $_cache_key = CacheConst::CACHE_WEIXIN_KEY_RETURN_MSG.md5(json_encode(array($mp_id, $key)));
- if (WeiXinMenuConst::IS_MENU_2 == $is_menu) {
- $_cache_key .= '_menu';
- }
- $_rdata = json_decode(Cache::get($_cache_key), true);
- if (!empty($_rdata)) {
- return $_rdata;
- }
- $_map = [
- 'oa_id' => $mp_id,
- 'is_menu' => $is_menu,
- 'key' => $key
- ];
- $_rdata = (new MpMenuModel())->where($_map)->value('return_msg');
- if (!empty($_rdata)) {
- Cache::set($_cache_key, json_encode($_rdata));
- }
- return $_rdata;
- }
- }
|