更新
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use app\common\service\qywx\QywxCustomerAcquisitionLinkService;
|
||||
|
||||
require dirname(__DIR__) . '/vendor/autoload.php';
|
||||
|
||||
$assert = static function (bool $condition, string $message): void {
|
||||
if (!$condition) {
|
||||
throw new RuntimeException($message);
|
||||
}
|
||||
};
|
||||
|
||||
$base = 'https://work.weixin.qq.com/ca/cawcdea778939b9097';
|
||||
$channelUrl = QywxCustomerAcquisitionLinkService::withCustomerChannel($base, 'zyt_pool:123');
|
||||
$assert(
|
||||
$channelUrl === $base . '?customer_channel=zyt_pool:123',
|
||||
'官方获客链接未按约定追加 customer_channel'
|
||||
);
|
||||
|
||||
$replaced = QywxCustomerAcquisitionLinkService::withCustomerChannel(
|
||||
$base . '?foo=1&customer_channel=old#wechat_redirect',
|
||||
'zyt_pool:456'
|
||||
);
|
||||
$assert(
|
||||
$replaced === $base . '?foo=1&customer_channel=zyt_pool:456#wechat_redirect',
|
||||
'已有 customer_channel 未被安全替换'
|
||||
);
|
||||
$assert(
|
||||
QywxCustomerAcquisitionLinkService::withCustomerChannel('https://example.com/ca/test', 'zyt_pool:1') === '',
|
||||
'非企业微信获客链接不应生成渠道地址'
|
||||
);
|
||||
$assert(
|
||||
QywxCustomerAcquisitionLinkService::withCustomerChannel($base, str_repeat('a', 65)) === '',
|
||||
'超过 64 字节的渠道标识不应被接受'
|
||||
);
|
||||
|
||||
$officialDetail = QywxCustomerAcquisitionLinkService::normaliseRemoteResponse([
|
||||
'errcode' => 0,
|
||||
'errmsg' => 'ok',
|
||||
'link' => [
|
||||
'link_name' => '官网获客',
|
||||
'url' => $base,
|
||||
'create_time' => 1787610000,
|
||||
'skip_verify' => true,
|
||||
],
|
||||
'range' => [
|
||||
'user_list' => ['HuoYiSheng', 'HuoYiSheng', 'Li'],
|
||||
'department_list' => ['2'],
|
||||
],
|
||||
'priority_option' => ['priority_type' => 1],
|
||||
], 'cawcdea778939b9097');
|
||||
$assert(
|
||||
$officialDetail['range_userids'] === ['HuoYiSheng', 'Li'],
|
||||
'get 接口根级 range.user_list 未被正确解析'
|
||||
);
|
||||
$assert(
|
||||
$officialDetail['range_department_ids'] === ['2'],
|
||||
'get 接口根级 range.department_list 未被正确解析'
|
||||
);
|
||||
$assert(
|
||||
($officialDetail['priority_option']['priority_type'] ?? 0) === 1,
|
||||
'get 接口根级 priority_option 未被正确解析'
|
||||
);
|
||||
$assert(
|
||||
isset($officialDetail['snapshot']['range']),
|
||||
'远端快照应保留完整响应,而不是只保留 link 节点'
|
||||
);
|
||||
|
||||
echo "QYWX_CUSTOMER_ACQUISITION_LINK_SERVICE_OK\n";
|
||||
Reference in New Issue
Block a user