Separate device type (android/ios) from token type (fcm/apns)

애플 기기에서도 FCM을 사용하여 푸시알림을 구현할 수 있으므로
디바이스의 운영체제와 무관하게 토큰 타입을 지정하도록 변경합니다.
기존에 등록된 토큰은 운영체제 및 포맷에 따라 자동 변환합니다.
This commit is contained in:
Kijin Sung 2020-10-28 00:37:55 +09:00
parent 61f6456b6c
commit ed7add6d9c
6 changed files with 39 additions and 30 deletions

View file

@ -290,10 +290,10 @@ class Push
$output = null; $output = null;
// Android FCM // Android FCM
if(count($tokens->android)) if(count($tokens->fcm))
{ {
$fcm_driver = $this->getDriver('fcm'); $fcm_driver = $this->getDriver('fcm');
$output = $fcm_driver->send($this, $tokens->android); $output = $fcm_driver->send($this, $tokens->fcm);
$this->sent = count($output->success) ? true : false; $this->sent = count($output->success) ? true : false;
$this->success_tokens = $output ? $output->success : []; $this->success_tokens = $output ? $output->success : [];
$this->deleted_tokens = $output ? $output->invalid : []; $this->deleted_tokens = $output ? $output->invalid : [];
@ -303,10 +303,10 @@ class Push
} }
// iOS APNs // iOS APNs
if(count($tokens->ios)) if(count($tokens->apns))
{ {
$apns_driver =$this->getDriver('apns'); $apns_driver =$this->getDriver('apns');
$output = $apns_driver->send($this, $tokens->ios); $output = $apns_driver->send($this, $tokens->apns);
$this->sent = count($output->success) ? true : false; $this->sent = count($output->success) ? true : false;
$this->success_tokens += $output ? $output->success : []; $this->success_tokens += $output ? $output->success : [];
$this->deleted_tokens += $output ? $output->invalid : []; $this->deleted_tokens += $output ? $output->invalid : [];
@ -339,26 +339,25 @@ class Push
*/ */
protected function _getDeviceTokens() protected function _getDeviceTokens()
{ {
$member_srl_list = $this->getRecipients();
$result = new \stdClass; $result = new \stdClass;
$result->android = []; $result->fcm = [];
$result->ios = []; $result->apns = [];
$args = new \stdClass; $args = new \stdClass;
$args->member_srl = $member_srl_list; $args->member_srl = $this->getRecipients();
$args->device_type = []; $args->device_token_type = [];
$driver_types = config('push.types') ?: array(); $driver_types = config('push.types') ?: array();
if(!count($driver_types))
{
return $result;
}
if(isset($driver_types['fcm'])) if(isset($driver_types['fcm']))
{ {
$args->device_type[] = 'android'; $args->device_token_type[] = 'fcm';
} }
if(isset($driver_types['apns'])) if(isset($driver_types['apns']))
{ {
$args->device_type[] = 'ios'; $args->device_token_type[] = 'apns';
}
if(!count($args->device_token_type))
{
return $result;
} }
$output = executeQueryArray('member.getMemberDeviceTokensByMemberSrl', $args); $output = executeQueryArray('member.getMemberDeviceTokensByMemberSrl', $args);
@ -369,7 +368,7 @@ class Push
foreach($output->data as $row) foreach($output->data as $row)
{ {
$result->{$row->device_type}[] = $row->device_token; $result->{$row->device_token_type}[] = $row->device_token;
} }
return $result; return $result;

View file

@ -200,6 +200,8 @@ class member extends ModuleObject {
if(!$oDB->isIndexExists('member_nickname_log', 'idx_after_nick_name')) return true; if(!$oDB->isIndexExists('member_nickname_log', 'idx_after_nick_name')) return true;
if(!$oDB->isIndexExists('member_nickname_log', 'idx_user_id')) return true; if(!$oDB->isIndexExists('member_nickname_log', 'idx_user_id')) return true;
if(!$oDB->isColumnExists('member_devices', 'device_token_type')) return true;
$config = ModuleModel::getModuleConfig('member'); $config = ModuleModel::getModuleConfig('member');
// Check members with phone country in old format // Check members with phone country in old format
@ -372,6 +374,15 @@ class member extends ModuleObject {
$oDB->addIndex('member_nickname_log', 'idx_user_id', array('user_id')); $oDB->addIndex('member_nickname_log', 'idx_user_id', array('user_id'));
} }
// Add device token type 2020.10.28
if(!$oDB->isColumnExists('member_devices', 'device_token_type'))
{
$oDB->addColumn('member_devices', 'device_token_type', 'varchar', '20', '', true, 'device_token');
$oDB->addIndex('member_devices', 'idx_device_token_type', array('device_token_type'));
$oDB->query("UPDATE member_devices SET device_token_type = 'fcm' WHERE device_type = 'android' OR LENGTH(device_token) > 64");
$oDB->query("UPDATE member_devices SET device_token_type = 'apns' WHERE device_type = 'ios' AND LENGTH(device_token) = 64");
}
$config = ModuleModel::getModuleConfig('member'); $config = ModuleModel::getModuleConfig('member');
$changed = false; $changed = false;

View file

@ -68,7 +68,7 @@ class memberController extends member
$args = new stdClass(); $args = new stdClass();
$args->member_srl = $member_info->member_srl; $args->member_srl = $member_info->member_srl;
executeQuery('member.deleteAuthMail', $args); executeQuery('member.deleteAuthMail', $args);
if(!$config->after_login_url) if(!$config->after_login_url)
{ {
$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', ''); $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', '');
@ -99,6 +99,7 @@ class memberController extends member
if(!$password && !$allow_guest_device) return new BaseObject(-1, 'NULL_PASSWORD'); if(!$password && !$allow_guest_device) return new BaseObject(-1, 'NULL_PASSWORD');
if(!$device_token) return new BaseObject(-1, 'NULL_DEVICE_TOKEN'); if(!$device_token) return new BaseObject(-1, 'NULL_DEVICE_TOKEN');
// Get device information
$browserInfo = Rhymix\Framework\UA::getBrowserInfo(); $browserInfo = Rhymix\Framework\UA::getBrowserInfo();
$device_type = strtolower($browserInfo->os); $device_type = strtolower($browserInfo->os);
$device_version = $browserInfo->os_version; $device_version = $browserInfo->os_version;
@ -107,23 +108,18 @@ class memberController extends member
$device_model = escape($browserInfo->device); $device_model = escape($browserInfo->device);
} }
if('ios' === $device_type) // Detect device token type
if (preg_match('/^[0-9a-z]{64}$/', $device_token))
{ {
if(!preg_match("/^[0-9a-z]{64}$/", $device_token)) $device_token_type = 'apns';
{
return new BaseObject(-1, 'INVALID_DEVICE_TOKEN');
}
} }
elseif('android' === $device_type) elseif (preg_match('/^[0-9a-zA-Z:_-]+$/', $device_token) && strlen($device_token) > 64)
{ {
if(!preg_match("/^[0-9a-zA-Z:_-]+$/", $device_token)) $device_token_type = 'fcm';
{
return new BaseObject(-1, 'INVALID_DEVICE_TOKEN');
}
} }
else else
{ {
return new BaseObject(-1, 'NOT_SUPPORTED_OS'); return new BaseObject(-1, 'INVALID_DEVICE_TOKEN');
} }
if($user_id && $password) if($user_id && $password)
@ -151,6 +147,7 @@ class memberController extends member
$args->device_srl = getNextSequence(); $args->device_srl = getNextSequence();
$args->member_srl = $member_srl; $args->member_srl = $member_srl;
$args->device_token = $device_token; $args->device_token = $device_token;
$args->device_token_type = $device_token_type;
$args->device_key = $device_key; $args->device_key = $device_key;
$args->device_type = $device_type; $args->device_type = $device_type;
$args->device_version = $device_version; $args->device_version = $device_version;

View file

@ -4,10 +4,10 @@
</tables> </tables>
<columns> <columns>
<column name="device_token" /> <column name="device_token" />
<column name="device_type" /> <column name="device_token_type" />
</columns> </columns>
<conditions> <conditions>
<condition operation="in" column="member_srl" var="member_srl" notnull="notnull" /> <condition operation="in" column="member_srl" var="member_srl" notnull="notnull" />
<condition operation="in" column="device_type" var="device_type" pipe="and" /> <condition operation="in" column="device_token_type" var="device_token_type" pipe="and" />
</conditions> </conditions>
</query> </query>

View file

@ -6,6 +6,7 @@
<column name="device_srl" var="device_srl" notnull="notnull" /> <column name="device_srl" var="device_srl" notnull="notnull" />
<column name="member_srl" var="member_srl" notnull="notnull" /> <column name="member_srl" var="member_srl" notnull="notnull" />
<column name="device_token" var="device_token" notnull="notnull" /> <column name="device_token" var="device_token" notnull="notnull" />
<column name="device_token_type" var="device_token_type" notnull="notnull" />
<column name="device_key" var="device_key" notnull="notnull" /> <column name="device_key" var="device_key" notnull="notnull" />
<column name="device_type" var="device_type" notnull="notnull" /> <column name="device_type" var="device_type" notnull="notnull" />
<column name="device_version" var="device_version" notnull="notnull" /> <column name="device_version" var="device_version" notnull="notnull" />

View file

@ -2,6 +2,7 @@
<column name="device_srl" type="number" notnull="notnull" primary_key="primary_key" /> <column name="device_srl" type="number" notnull="notnull" primary_key="primary_key" />
<column name="member_srl" type="number" notnull="notnull" index="idx_member_srl" /> <column name="member_srl" type="number" notnull="notnull" index="idx_member_srl" />
<column name="device_token" type="varchar" size="191" notnull="notnull" unique="unique_device_token" /> <column name="device_token" type="varchar" size="191" notnull="notnull" unique="unique_device_token" />
<column name="device_token_type" type="varchar" size="20" notnull="notnull" index="idx_device_token_type" />
<column name="device_key" type="char" size="64" notnull="notnull" /> <column name="device_key" type="char" size="64" notnull="notnull" />
<column name="device_type" type="varchar" size="20" notnull="notnull" index="idx_device_type" /> <column name="device_type" type="varchar" size="20" notnull="notnull" index="idx_device_type" />
<column name="device_version" type="varchar" size="20" notnull="notnull" /> <column name="device_version" type="varchar" size="20" notnull="notnull" />