|
@@ -46,7 +46,7 @@ class WechatCommonService extends BaseService
|
|
return self::handleEvent($app, $wechatInfoId, $appid, $message);
|
|
return self::handleEvent($app, $wechatInfoId, $appid, $message);
|
|
case 'text':
|
|
case 'text':
|
|
// 更新用户活跃时间
|
|
// 更新用户活跃时间
|
|
- self::updateUserActivityTime($app, $appid, $message['FromUserName']);
|
|
|
|
|
|
+ self::updateUserActivityTime($app,$wechatInfoId ,$appid, $message['FromUserName']);
|
|
return self::handleTextMessage($wechatInfoId, $message);
|
|
return self::handleTextMessage($wechatInfoId, $message);
|
|
// case 'image':
|
|
// case 'image':
|
|
// return '收到图片消息';
|
|
// return '收到图片消息';
|
|
@@ -92,17 +92,18 @@ class WechatCommonService extends BaseService
|
|
* @param $openId
|
|
* @param $openId
|
|
* date 2023/07/10 18:30
|
|
* date 2023/07/10 18:30
|
|
*/
|
|
*/
|
|
- private static function updateUserActivityTime($app, $appid, $openId)
|
|
|
|
|
|
+ private static function updateUserActivityTime($app, $appid, $openId, $wechatInfoId)
|
|
{
|
|
{
|
|
|
|
|
|
$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,
|
|
|
|
+ 'gzh_id' => $wechatInfoId,
|
|
'active_at' => time(),
|
|
'active_at' => time(),
|
|
];
|
|
];
|
|
if (is_empty($info)) {
|
|
if (is_empty($info)) {
|
|
- $data = self::getUserInfo($app,$appid,$openId);
|
|
|
|
|
|
+ $data = self::getUserInfo($app,$appid,$openId,$wechatInfoId);
|
|
$data['active_at'] = time();
|
|
$data['active_at'] = time();
|
|
}else{
|
|
}else{
|
|
if ($info->uid == 0 && !empty($info->unionid)){
|
|
if ($info->uid == 0 && !empty($info->unionid)){
|
|
@@ -122,13 +123,14 @@ class WechatCommonService extends BaseService
|
|
* @param $is_gz
|
|
* @param $is_gz
|
|
* date 2023/07/10 18:31
|
|
* date 2023/07/10 18:31
|
|
*/
|
|
*/
|
|
- private static function updateUserInfo($app, $appid, $openId, $is_gz)
|
|
|
|
|
|
+ private static function updateUserInfo($app, $appid, $openId, $wechatInfoId, $is_gz)
|
|
{
|
|
{
|
|
|
|
|
|
if (!$is_gz) {
|
|
if (!$is_gz) {
|
|
$data = [
|
|
$data = [
|
|
'mp_openid' => $openId,
|
|
'mp_openid' => $openId,
|
|
'gzh_appid' => $appid,
|
|
'gzh_appid' => $appid,
|
|
|
|
+ 'gzh_id' => $wechatInfoId,
|
|
'active_at' => time(),
|
|
'active_at' => time(),
|
|
'is_subscribe' => 0,
|
|
'is_subscribe' => 0,
|
|
'unsubscribe_at' => get_date(),
|
|
'unsubscribe_at' => get_date(),
|
|
@@ -137,6 +139,7 @@ class WechatCommonService extends BaseService
|
|
$data = [
|
|
$data = [
|
|
'mp_openid' => $openId,
|
|
'mp_openid' => $openId,
|
|
'gzh_appid' => $appid,
|
|
'gzh_appid' => $appid,
|
|
|
|
+ 'gzh_id' => $wechatInfoId,
|
|
'is_subscribe' => 1,
|
|
'is_subscribe' => 1,
|
|
'subscribe_time' => time(),
|
|
'subscribe_time' => time(),
|
|
'subscribe_time_str' => get_date(),
|
|
'subscribe_time_str' => get_date(),
|
|
@@ -144,7 +147,7 @@ class WechatCommonService extends BaseService
|
|
}
|
|
}
|
|
$info = WechatOfficialUserInfo::query()->where('mp_openid', $openId)->where('gzh_appid', $appid)->first();
|
|
$info = WechatOfficialUserInfo::query()->where('mp_openid', $openId)->where('gzh_appid', $appid)->first();
|
|
if ($is_gz == true && is_empty($info)) {
|
|
if ($is_gz == true && is_empty($info)) {
|
|
- $data = self::getUserInfo($app,$appid,$openId);
|
|
|
|
|
|
+ $data = self::getUserInfo($app,$appid,$openId,$wechatInfoId);
|
|
WechatOfficialUserInfo::updateOrCreate(['mp_openid' => $data['mp_openid'], 'gzh_appid' => $data['gzh_appid']], $data);
|
|
WechatOfficialUserInfo::updateOrCreate(['mp_openid' => $data['mp_openid'], 'gzh_appid' => $data['gzh_appid']], $data);
|
|
}else{
|
|
}else{
|
|
if (!is_empty($info)){
|
|
if (!is_empty($info)){
|
|
@@ -164,11 +167,12 @@ class WechatCommonService extends BaseService
|
|
* @param $openId
|
|
* @param $openId
|
|
* date 2023/07/10 18:31
|
|
* date 2023/07/10 18:31
|
|
*/
|
|
*/
|
|
- protected static function getUserInfo($app,$appid,$openId){
|
|
|
|
|
|
+ protected static function getUserInfo($app,$appid,$openId, $wechatInfoId){
|
|
$user = $app->user->get($openId);
|
|
$user = $app->user->get($openId);
|
|
$data = [
|
|
$data = [
|
|
'mp_openid' => $openId,
|
|
'mp_openid' => $openId,
|
|
'gzh_appid' => $appid,
|
|
'gzh_appid' => $appid,
|
|
|
|
+ 'gzh_id' => $wechatInfoId,
|
|
'unionid' => $user['unionid'],
|
|
'unionid' => $user['unionid'],
|
|
'is_subscribe' => $user['subscribe'],
|
|
'is_subscribe' => $user['subscribe'],
|
|
'subscribe_time' => $user['subscribe_time'],
|
|
'subscribe_time' => $user['subscribe_time'],
|
|
@@ -191,10 +195,10 @@ class WechatCommonService extends BaseService
|
|
{
|
|
{
|
|
switch ($message['Event']) {
|
|
switch ($message['Event']) {
|
|
case 'unsubscribe':
|
|
case 'unsubscribe':
|
|
- self::updateUserInfo($app, $appid, $message['FromUserName'], false);
|
|
|
|
|
|
+ self::updateUserInfo($app, $appid, $message['FromUserName'], $wechatInfoId,false);
|
|
return '取消关注';
|
|
return '取消关注';
|
|
case 'subscribe':
|
|
case 'subscribe':
|
|
- self::updateUserInfo($app, $appid, $message['FromUserName'], true);
|
|
|
|
|
|
+ self::updateUserInfo($app, $appid, $message['FromUserName'],$wechatInfoId, true);
|
|
return WechatSubscribeService::getContent($wechatInfoId);
|
|
return WechatSubscribeService::getContent($wechatInfoId);
|
|
default:
|
|
default:
|
|
return '收到其它消息';
|
|
return '收到其它消息';
|