OaReturnMsg.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * OaReturnMsg.php UTF-8
  4. * 微信回复内容处理程序
  5. *
  6. * @date : 2018/9/27 14:40
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : chenbingling <cbl@huosdk.com>
  10. * @version : HuoMp 1.0
  11. */
  12. namespace huoMpMsg\controller;
  13. use huo\controller\wap\Option;
  14. use huolib\constant\CacheConst;
  15. use huolib\constant\OptionConst;
  16. use huolib\constant\WeiXinMenuConst;
  17. use huomp\model\weixin\MpConfModel;
  18. use huoMpMsg\model\MpMenuModel;
  19. use think\Cache;
  20. class OaReturnMsg {
  21. /**
  22. * 获取关注回复内容
  23. *
  24. * @param $mp_id
  25. *
  26. * @return string
  27. */
  28. public function getSubscribeMsg($mp_id) {
  29. $_conf_id = (new MpConfModel())->getIdByMpId($mp_id);
  30. if (empty($_conf_id)) {
  31. return '';
  32. }
  33. $_setting_name = OptionConst::WEIXIN_SUBSCRIBE_RETURN_MSG.$_conf_id;
  34. $_m = new Option();
  35. $_item = $_m->getOptionData($_setting_name, 1, true);
  36. if (!empty($_item['option_value'])) {
  37. $_item['option_value'] = json_decode($_item['option_value'], true);
  38. }
  39. if (!empty($_item['option_value']['text'])) {
  40. return $_item['option_value']['text'];
  41. }
  42. return '';
  43. }
  44. /**
  45. * 获取关键词自定义回复内容
  46. *
  47. * @param string $mp_id 公众号app_id
  48. * @param string $key 关键词
  49. * @param int $is_menu 是否菜单
  50. *
  51. * @return mixed|string
  52. */
  53. public function getKeyReturnMsg($mp_id, $key, $is_menu = WeiXinMenuConst::IS_MENU_1) {
  54. if (empty($key)) {
  55. return '';
  56. }
  57. $_cache_key = CacheConst::CACHE_WEIXIN_KEY_RETURN_MSG.md5(json_encode(array($mp_id, $key)));
  58. if (WeiXinMenuConst::IS_MENU_2 == $is_menu) {
  59. $_cache_key .= '_menu';
  60. }
  61. $_rdata = json_decode(Cache::get($_cache_key), true);
  62. if (!empty($_rdata)) {
  63. return $_rdata;
  64. }
  65. $_map = [
  66. 'oa_id' => $mp_id,
  67. 'is_menu' => $is_menu,
  68. 'key' => $key
  69. ];
  70. $_rdata = (new MpMenuModel())->where($_map)->value('return_msg');
  71. if (!empty($_rdata)) {
  72. Cache::set($_cache_key, json_encode($_rdata));
  73. }
  74. return $_rdata;
  75. }
  76. }