Merge pull request 'fix: 阿里云 H5 认证提交 MetaInfo' (#348) from worktree-identity-form-simplify into main
Reviewed-on: CYL/wordpress-theme-aksrt#348
This commit is contained in:
commit
ab81ae992b
3 files changed
+39
-4
No files matched your search
@@ -27,6 +27,33 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loadScript(src) {
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
var existing = document.querySelector('script[src="' + src + '"]');
|
||||||
|
if (existing) {
|
||||||
|
if (existing.dataset.loaded === '1') return resolve();
|
||||||
|
existing.addEventListener('load', resolve, { once: true });
|
||||||
|
existing.addEventListener('error', reject, { once: true });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var script = document.createElement('script');
|
||||||
|
script.src = src;
|
||||||
|
script.async = true;
|
||||||
|
script.onload = function () { script.dataset.loaded = '1'; resolve(); };
|
||||||
|
script.onerror = reject;
|
||||||
|
document.head.appendChild(script);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function aliyunMetaInfo(config) {
|
||||||
|
if (config.provider !== 'aliyun') return Promise.resolve('');
|
||||||
|
return loadScript('https://o.alicdn.com/yd-cloudauth/cloudauth-cdn/jsvm_all.js').then(function () {
|
||||||
|
if (typeof window.getMetaInfo !== 'function') throw new Error('阿里云 MetaInfo 组件未加载成功');
|
||||||
|
var meta = window.getMetaInfo();
|
||||||
|
return typeof meta === 'string' ? meta : JSON.stringify(meta || {});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function init(root) {
|
function init(root) {
|
||||||
if (!root || root.dataset.identityBound === '1') return;
|
if (!root || root.dataset.identityBound === '1') return;
|
||||||
root.dataset.identityBound = '1';
|
root.dataset.identityBound = '1';
|
||||||
@@ -107,10 +134,13 @@
|
|||||||
payload.client_request_id = uuid();
|
payload.client_request_id = uuid();
|
||||||
var button = createForm.querySelector('[type="submit"]');
|
var button = createForm.querySelector('[type="submit"]');
|
||||||
if (button) button.disabled = true;
|
if (button) button.disabled = true;
|
||||||
request(config.restBase, config, {
|
aliyunMetaInfo(config).then(function (metaInfo) {
|
||||||
method: 'POST',
|
if (metaInfo) payload.meta_info = metaInfo;
|
||||||
headers: { 'Content-Type': 'application/json' },
|
return request(config.restBase, config, {
|
||||||
body: JSON.stringify(payload)
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify(payload)
|
||||||
|
});
|
||||||
}).then(render).catch(function (error) {
|
}).then(render).catch(function (error) {
|
||||||
var node = createForm.querySelector('[data-auth-message]');
|
var node = createForm.querySelector('[data-auth-message]');
|
||||||
if (node) node.textContent = error.message;
|
if (node) node.textContent = error.message;
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ $config = [
|
|||||||
'nonce' => wp_create_nonce('wp_rest'),
|
'nonce' => wp_create_nonce('wp_rest'),
|
||||||
'currentUuid' => $locks_application ? (string) ($record['application_uuid'] ?? '') : '',
|
'currentUuid' => $locks_application ? (string) ($record['application_uuid'] ?? '') : '',
|
||||||
'currentStage' => $locks_application ? $stage : '',
|
'currentStage' => $locks_application ? $stage : '',
|
||||||
|
'provider' => sanitize_key((string) ($settings['provider'] ?? 'aliyun')),
|
||||||
'allowManual' => !empty($settings['allow_manual_fallback']),
|
'allowManual' => !empty($settings['allow_manual_fallback']),
|
||||||
];
|
];
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -138,6 +138,10 @@ final class AliyunProvider implements ProviderInterface {
|
|||||||
'CertName' => (string) ($request['person_name'] ?? ''),
|
'CertName' => (string) ($request['person_name'] ?? ''),
|
||||||
'CertNo' => preg_replace('/\s+/', '', (string) ($request['id_number'] ?? '')),
|
'CertNo' => preg_replace('/\s+/', '', (string) ($request['id_number'] ?? '')),
|
||||||
];
|
];
|
||||||
|
$meta_info = trim((string) ($request['meta_info'] ?? ''));
|
||||||
|
if ($meta_info !== '') {
|
||||||
|
$params['MetaInfo'] = $meta_info;
|
||||||
|
}
|
||||||
$return_url = esc_url_raw((string) ($request['return_url'] ?? ''));
|
$return_url = esc_url_raw((string) ($request['return_url'] ?? ''));
|
||||||
if ($this->is_public_https_url($return_url)) {
|
if ($this->is_public_https_url($return_url)) {
|
||||||
$params['ReturnUrl'] = $return_url;
|
$params['ReturnUrl'] = $return_url;
|
||||||
|
|||||||
Reference in new issue
Block a user