|
@@ -9,7 +9,9 @@
|
|
|
|
|
|
namespace Modules\WechatPlatform\Services;
|
|
namespace Modules\WechatPlatform\Services;
|
|
|
|
|
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
use Modules\Common\Services\BaseService;
|
|
use Modules\Common\Services\BaseService;
|
|
|
|
+use Modules\WechatPlatform\Models\WechatOfficialUserInfo;
|
|
|
|
|
|
class WechatCommonService extends BaseService
|
|
class WechatCommonService extends BaseService
|
|
{
|
|
{
|
|
@@ -31,12 +33,13 @@ class WechatCommonService extends BaseService
|
|
* 微信消息推送处理
|
|
* 微信消息推送处理
|
|
* name: handleMessage
|
|
* name: handleMessage
|
|
* @param $app
|
|
* @param $app
|
|
- * @param $wechatAppId 微信公众号授权信息id
|
|
|
|
|
|
+ * @param $wechatInfoId 公众号授权信息id
|
|
|
|
+ * @param $appid 公众号APPID
|
|
* @param $message
|
|
* @param $message
|
|
* @return string|void
|
|
* @return string|void
|
|
* date 2023/07/10 16:04
|
|
* date 2023/07/10 16:04
|
|
*/
|
|
*/
|
|
- public static function handleMessage($app,$wechatAppId, $message)
|
|
|
|
|
|
+ public static function handleMessage($app,$wechatInfoId,$appid, $message)
|
|
{
|
|
{
|
|
switch ($message['MsgType']) {
|
|
switch ($message['MsgType']) {
|
|
case 'event':
|
|
case 'event':
|
|
@@ -44,8 +47,8 @@ class WechatCommonService extends BaseService
|
|
break;
|
|
break;
|
|
case 'text':
|
|
case 'text':
|
|
// 更新用户活跃时间
|
|
// 更新用户活跃时间
|
|
- self::updateUserActivityTime($app,$message['FromUserName']);
|
|
|
|
- return self::handleTextMessage($wechatAppId,$message);
|
|
|
|
|
|
+ self::updateUserActivityTime($app,$appid,$message['FromUserName']);
|
|
|
|
+ return self::handleTextMessage($wechatInfoId,$message);
|
|
case 'image':
|
|
case 'image':
|
|
return '收到图片消息';
|
|
return '收到图片消息';
|
|
break;
|
|
break;
|
|
@@ -63,10 +66,12 @@ class WechatCommonService extends BaseService
|
|
break;
|
|
break;
|
|
case 'file':
|
|
case 'file':
|
|
return '收到文件消息';
|
|
return '收到文件消息';
|
|
|
|
+
|
|
default:
|
|
default:
|
|
return '收到其它消息';
|
|
return '收到其它消息';
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
+ return "";
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -79,21 +84,38 @@ class WechatCommonService extends BaseService
|
|
private static function handleTextMessage($wechatAppId, $msg)
|
|
private static function handleTextMessage($wechatAppId, $msg)
|
|
{
|
|
{
|
|
$content = $msg['Content'];
|
|
$content = $msg['Content'];
|
|
- myLog("wx-xiaoxi")->info('关键词处理'.$content);
|
|
|
|
- myLog("wx-xiaoxi")->info($msg);
|
|
|
|
if ($content == "pk"){
|
|
if ($content == "pk"){
|
|
return $msg['FromUserName'] ;
|
|
return $msg['FromUserName'] ;
|
|
}
|
|
}
|
|
$back = WechatKeywordsService::getKeywordsByWords($content,$wechatAppId);
|
|
$back = WechatKeywordsService::getKeywordsByWords($content,$wechatAppId);
|
|
$back = $back ?: "";
|
|
$back = $back ?: "";
|
|
- myLog("wx-xiaoxi")->info(['title' => "回复信息",'wechatAppId' => $wechatAppId,'msg' => $content,'back' => $back]);
|
|
|
|
return $back;
|
|
return $back;
|
|
}
|
|
}
|
|
|
|
|
|
- private static function updateUserActivityTime($app, $openId)
|
|
|
|
|
|
+ private static function updateUserActivityTime($app,$appid,$opendId)
|
|
{
|
|
{
|
|
- $user = $app->user->get($openId);
|
|
|
|
- myLog("wx-xiaoxi")->info("拉取用户信息");
|
|
|
|
- myLog("wx-xiaoxi")->info($user);
|
|
|
|
|
|
+
|
|
|
|
+ $info = WechatOfficialUserInfo::query()->where('mp_openid',$opendId)->where('gzh_appid',$appid)->first();
|
|
|
|
+ $data = [
|
|
|
|
+ 'mp_openid' => $opendId,
|
|
|
|
+ 'gzh_appid' => $appid,
|
|
|
|
+ 'active_at' => time(),
|
|
|
|
+ ];
|
|
|
|
+ if (is_empty($info)){
|
|
|
|
+ $user = $app->user->get();
|
|
|
|
+ $data = [
|
|
|
|
+ 'mp_openid' => $opendId,
|
|
|
|
+ 'gzh_appid' => $appid,
|
|
|
|
+ 'unionid' => $user['unionid'],
|
|
|
|
+ 'is_subscribe' => $user['subscribe'],
|
|
|
|
+ 'subscribe_time' => $user['subscribe_time'],
|
|
|
|
+ 'subscribe_time_str' => get_date($user['subscribe_time']),
|
|
|
|
+ 'active_at' => time(),
|
|
|
|
+ 'uid' => intval(DB::table('wechat_miniprogram_users')->where('unionid',$user['unionid'])->value('id')),
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+ WechatOfficialUserInfo::updateOrCreate(['mp_openid' => $data['mp_openid'],'gzh_appid' => $data['gzh_appid']],$data);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|