|
@@ -24,9 +24,9 @@ class WechatCommonService extends BaseService
|
|
* @param $sequence
|
|
* @param $sequence
|
|
* date 2023/07/07 11:52
|
|
* date 2023/07/07 11:52
|
|
*/
|
|
*/
|
|
- public static function getPlayPageUrl($videoId,$sequence)
|
|
|
|
|
|
+ public static function getPlayPageUrl($videoId, $sequence)
|
|
{
|
|
{
|
|
- return ['url' => "/pages/video/index?video_id={$videoId}&sequence={$sequence}"];
|
|
|
|
|
|
+ return ['url' => "/pages/video/index?video_id={$videoId}&sequence={$sequence}"];
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -39,7 +39,7 @@ class WechatCommonService extends BaseService
|
|
* @return string|void
|
|
* @return string|void
|
|
* date 2023/07/10 16:04
|
|
* date 2023/07/10 16:04
|
|
*/
|
|
*/
|
|
- public static function handleMessage($app,$wechatInfoId,$appid, $message)
|
|
|
|
|
|
+ public static function handleMessage($app, $wechatInfoId, $appid, $message)
|
|
{
|
|
{
|
|
switch ($message['MsgType']) {
|
|
switch ($message['MsgType']) {
|
|
case 'event':
|
|
case 'event':
|
|
@@ -47,8 +47,8 @@ class WechatCommonService extends BaseService
|
|
break;
|
|
break;
|
|
case 'text':
|
|
case 'text':
|
|
// 更新用户活跃时间
|
|
// 更新用户活跃时间
|
|
- self::updateUserActivityTime($app,$appid,$message['FromUserName']);
|
|
|
|
- return self::handleTextMessage($wechatInfoId,$message);
|
|
|
|
|
|
+ self::updateUserActivityTime($app, $appid, $message['FromUserName']);
|
|
|
|
+ return self::handleTextMessage($wechatInfoId, $message);
|
|
case 'image':
|
|
case 'image':
|
|
return '收到图片消息';
|
|
return '收到图片消息';
|
|
break;
|
|
break;
|
|
@@ -61,12 +61,13 @@ class WechatCommonService extends BaseService
|
|
case 'location':
|
|
case 'location':
|
|
return '收到坐标消息';
|
|
return '收到坐标消息';
|
|
break;
|
|
break;
|
|
- case 'link':
|
|
|
|
- return '收到链接消息';
|
|
|
|
|
|
+ case 'unsubscribe':
|
|
|
|
+ self::updateUserInfo($app, $appid, $message['FromUserName'], false);
|
|
|
|
+ return '取消关注';
|
|
break;
|
|
break;
|
|
- case 'file':
|
|
|
|
- return '收到文件消息';
|
|
|
|
-
|
|
|
|
|
|
+ case 'subscribe':
|
|
|
|
+ self::updateUserInfo($app, $appid, $message['FromUserName'], true);
|
|
|
|
+ return self::handleSubscribeMessage($wechatInfoId, $message);
|
|
default:
|
|
default:
|
|
return '收到其它消息';
|
|
return '收到其它消息';
|
|
break;
|
|
break;
|
|
@@ -84,37 +85,111 @@ class WechatCommonService extends BaseService
|
|
private static function handleTextMessage($wechatAppId, $msg)
|
|
private static function handleTextMessage($wechatAppId, $msg)
|
|
{
|
|
{
|
|
$content = $msg['Content'];
|
|
$content = $msg['Content'];
|
|
- if ($content == "pk"){
|
|
|
|
- return $msg['FromUserName'] ;
|
|
|
|
|
|
+ if ($content == "pk") {
|
|
|
|
+ return $msg['FromUserName'];
|
|
}
|
|
}
|
|
- $back = WechatKeywordsService::getKeywordsByWords($content,$wechatAppId);
|
|
|
|
- $back = $back ?: "";
|
|
|
|
- return $back;
|
|
|
|
|
|
+ $back = WechatKeywordsService::getKeywordsByWords($content, $wechatAppId);
|
|
|
|
+ return $back ?: "";
|
|
}
|
|
}
|
|
|
|
|
|
- private static function updateUserActivityTime($app,$appid,$openId)
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 更新用户活跃时间
|
|
|
|
+ * name: updateUserActivityTime
|
|
|
|
+ * @param $app
|
|
|
|
+ * @param $appid
|
|
|
|
+ * @param $openId
|
|
|
|
+ * date 2023/07/10 18:30
|
|
|
|
+ */
|
|
|
|
+ private static function updateUserActivityTime($app, $appid, $openId)
|
|
{
|
|
{
|
|
|
|
|
|
- $info = WechatOfficialUserInfo::query()->where('mp_openid',$openId)->where('gzh_appid',$appid)->first();
|
|
|
|
|
|
+ $info = WechatOfficialUserInfo::query()->where('mp_openid', $openId)->where('gzh_appid', $appid)->first();
|
|
$data = [
|
|
$data = [
|
|
'mp_openid' => $openId,
|
|
'mp_openid' => $openId,
|
|
'gzh_appid' => $appid,
|
|
'gzh_appid' => $appid,
|
|
- 'active_at' => time(),
|
|
|
|
|
|
+ 'active_at' => time(),
|
|
];
|
|
];
|
|
- if (is_empty($info)){
|
|
|
|
- $user = $app->user->get($openId);
|
|
|
|
|
|
+ if (is_empty($info)) {
|
|
|
|
+ $data = self::getUserInfo($app,$appid,$openId);
|
|
|
|
+ }else{
|
|
|
|
+ if ($info->uid == 0){
|
|
|
|
+ $data['uid'] = intval(DB::table('wechat_miniprogram_users')->where('unionid', $info->unionid)->value('id'));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ WechatOfficialUserInfo::updateOrCreate(['mp_openid' => $data['mp_openid'], 'gzh_appid' => $data['gzh_appid']], $data);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 更新用户时间
|
|
|
|
+ * name: updateUserInfo
|
|
|
|
+ * @param $app
|
|
|
|
+ * @param $appid
|
|
|
|
+ * @param $openId
|
|
|
|
+ * @param $is_gz
|
|
|
|
+ * date 2023/07/10 18:31
|
|
|
|
+ */
|
|
|
|
+ private static function updateUserInfo($app, $appid, $openId, $is_gz)
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ if (!$is_gz) {
|
|
|
|
+ $data = [
|
|
|
|
+ 'mp_openid' => $openId,
|
|
|
|
+ 'gzh_appid' => $appid,
|
|
|
|
+ 'active_at' => time(),
|
|
|
|
+ 'is_subscribe' => 0,
|
|
|
|
+ 'unsubscribe_at' => get_date(),
|
|
|
|
+ ];
|
|
|
|
+ } else {
|
|
$data = [
|
|
$data = [
|
|
'mp_openid' => $openId,
|
|
'mp_openid' => $openId,
|
|
'gzh_appid' => $appid,
|
|
'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')),
|
|
|
|
|
|
+ 'is_subscribe' => 1,
|
|
|
|
+ 'subscribe_time' => time(),
|
|
|
|
+ 'subscribe_time_str' => get_date(),
|
|
];
|
|
];
|
|
}
|
|
}
|
|
- WechatOfficialUserInfo::updateOrCreate(['mp_openid' => $data['mp_openid'],'gzh_appid' => $data['gzh_appid']],$data);
|
|
|
|
|
|
+ $info = WechatOfficialUserInfo::query()->where('mp_openid', $openId)->where('gzh_appid', $appid)->first();
|
|
|
|
+ if ($is_gz == true && is_empty($info)) {
|
|
|
|
+ $data = self::getUserInfo($app,$appid,$openId);
|
|
|
|
+ WechatOfficialUserInfo::updateOrCreate(['mp_openid' => $data['mp_openid'], 'gzh_appid' => $data['gzh_appid']], $data);
|
|
|
|
+ }else{
|
|
|
|
+
|
|
|
|
+ if (!is_empty($info)){
|
|
|
|
+ if ($info->uid == 0){
|
|
|
|
+ $data['uid'] = intval(DB::table('wechat_miniprogram_users')->where('unionid', $info->unionid)->value('id'));
|
|
|
|
+ }
|
|
|
|
+ WechatOfficialUserInfo::updateOrCreate(['mp_openid' => $data['mp_openid'], 'gzh_appid' => $data['gzh_appid']], $data);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 构建用户数据
|
|
|
|
+ * name: getUserInfo
|
|
|
|
+ * @param $app
|
|
|
|
+ * @param $appid
|
|
|
|
+ * @param $openId
|
|
|
|
+ * date 2023/07/10 18:31
|
|
|
|
+ */
|
|
|
|
+ protected static function getUserInfo($app,$appid,$openId){
|
|
|
|
+ $user = $app->user->get($openId);
|
|
|
|
+ $data = [
|
|
|
|
+ 'mp_openid' => $openId,
|
|
|
|
+ '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')),
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static function handleSubscribeMessage($wechatInfoId)
|
|
|
|
+ {
|
|
|
|
+ $back = WechatSubscribeService::getContent($wechatAppId);
|
|
|
|
+ return $back ?: "";
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|