保存微信首次登录修复及当前生产可写预检

这个提交包含在:
mac 于 2026-11-13 01:14:36 +08:00 提交
1 父节点 8c2f226d43
当前提交 d944ad8652
10 个文件已更改
+987 -1

没有与搜索条件相匹配的文件

+13
查看文件
@@ -55,6 +55,19 @@ check(body(Dayu_Color_Online_LUTs::logout(new Request(array(),$restored['token']
$session=array('app_name'=>'DayuColor','device_uuid'=>$device,'expires_at'=>time()+120,'status'=>'pending','user_id'=>7);
$transients[$login]=$session;
check(body(Dayu_Color_Online_LUTs::exchange(new Request(array('session_key'=>$key,'device_uuid'=>$device))))['status']==='pending','pending login cannot mint a credential');
$bound=0;
check(body(Dayu_Color_Online_LUTs::exchange(new Request(array('session_key'=>$key,'device_uuid'=>$device))))['status']==='pending','first unbound device can wait for WeChat approval');
$transients[$login]['status']='approved';
check(denied(Dayu_Color_Online_LUTs::exchange(new Request(array('session_key'=>$key,'device_uuid'=>$device))),401),'approval cannot bypass missing UUID binding');
check(isset($transients[$login])&&!isset($options['dayu_color_lut_once_'.hash('sha256',$key)]),'missing binding does not consume the login session');
$transients[$login]=$session;$transients[$login]['status']='denied';$transients[$login]['message']='该 UUID 已绑定其他账号,请先解绑';
$failed=Dayu_Color_Online_LUTs::exchange(new Request(array('session_key'=>$key,'device_uuid'=>$device)));
check(denied($failed,401)&&$failed->message===$transients[$login]['message'],'callback denial immediately stops installed client polling with the actual reason');
$transients[$login]['status']='expired';
check(denied(Dayu_Color_Online_LUTs::exchange(new Request(array('session_key'=>$key,'device_uuid'=>$device))),401),'expired callback stops installed client polling');
$transients[$login]=$session;$transients[$login]['expires_at']=time()-1;
check(denied(Dayu_Color_Online_LUTs::exchange(new Request(array('session_key'=>$key,'device_uuid'=>$device))),401),'past session deadline stops polling');
$transients[$login]=$session;$bound=7;
$transients[$login]['app_name']='FCPXSoundEffects';check(denied(Dayu_Color_Online_LUTs::exchange(new Request(array('session_key'=>$key,'device_uuid'=>$device))),401),'another product login rejected');
$transients[$login]=$session;$transients[$login]['status']='approved';
$issued=Dayu_Color_Online_LUTs::exchange(new Request(array('session_key'=>$key,'device_uuid'=>$device)));$token=body($issued)['token']??'';
+84
查看文件
@@ -0,0 +1,84 @@
<?php
// Execute the actual theme callback with synthetic OAuth and WordPress services.
// Never load wp-config.php, contact WeChat, or read/change real accounts.
namespace Yurun\OAuthLogin\Weixin {
class OAuth2 {
public $http, $openid='synthetic-wechat-openid';
public function __construct(...$args) { $this->http=new \stdClass; }
public function getAccessToken($state) { return 'synthetic-provider-token'; }
public function getUserInfo() { return array('nickname'=>'测试用户', 'headimgurl'=>'https://example.invalid/avatar'); }
}
}
namespace {
define('ABSPATH', __DIR__.'/'); define('MINUTE_IN_SECONDS', 60);
class CallbackRedirect extends \RuntimeException {}
class CallbackRejected extends \RuntimeException {}
class LoginEvents {
public $events=array();
public function log_login_event($stage,$fields=array()) { $this->events[]=array('stage'=>$stage,'fields'=>$fields); }
}
class CallbackDB {
public $usermeta='synthetic_usermeta';
public function prepare(...$args) { return $args; }
public function get_var($query) { return 7; }
}
$wpdb=new CallbackDB;
$GLOBALS['dayu_macos_app_auth']=new LoginEvents;
$transients=array(); $checks=array();
function _cao($key) { return array('appid'=>'synthetic','appkey'=>'synthetic'); }
function home_url($path) { return 'https://dayu.media'.$path; }
function wp_parse_url($url) { return parse_url($url); }
function sanitize_text_field($value) { return trim(strip_tags($value)); }
function set_transient($key,$value,$ttl) { global $transients; $transients[$key]=$value; return true; }
function get_current_user_id() { return 0; }
function wp_set_current_user($id) {}
function wp_set_auth_cookie(...$args) {}
function get_user_by(...$args) { return (object)array('user_login'=>'synthetic-user'); }
function do_action(...$args) {}
function wp_safe_redirect($url) { throw new CallbackRedirect; }
function cao_wp_die(...$args) { throw new CallbackRejected; }
function is_wp_error($value) { return false; }
function check($passed,$name) {
global $checks;
$checks[]=array('name'=>$name,'pass'=>(bool)$passed);
if (!$passed) { fwrite(STDERR,'FAIL '.$name."\n"); exit(1); }
}
// Redirects throw before the production callback's exit statements.
function callback_proof($app, $overrides=array(), $host='dayu.media', $provider_state=true) {
global $transients;
$transients=array(); $GLOBALS['dayu_macos_app_auth']->events=array();
$query=array_merge(array('action'=>'app_wechat_auth_check','app_name'=>$app,
'fcpxqwen_session'=>str_repeat('a',40),'device_uuid'=>'00000000-0000-0000-0000-000000000001'),$overrides);
$_SESSION=array('oauth_rurl'=>'https://'.$host.'/wp-admin/admin-ajax.php?'.http_build_query($query));
if ($provider_state) { $_SESSION['YURUN_WEIXIN_STATE']='synthetic-state'; }
$_GET=array('code'=>'synthetic-code');
try { include $GLOBALS['callback_source']; } catch (CallbackRedirect $e) {} catch (CallbackRejected $e) {}
return $_SESSION['dayu_fcpx_wechat_oauth']??null;
}
$callback_source=$argv[1]??__DIR__.'/../wp-content/themes/ripro5/inc/oauth/weixin/callback.php';
session_start();
$proof=callback_proof('DayuColor');
check(is_array($proof),'DayuColor first scan writes OAuth proof without any prior UUID binding');
check($proof['session_hash']===hash('sha256',str_repeat('a',40))
&&$proof['device_hash']===hash('sha256','00000000-0000-0000-0000-000000000001')
&&$proof['openid_hash']===hash('sha256','synthetic-wechat-openid'),
'proof binds this login session, hardware UUID and provider identity');
check(abs(time()-$proof['issued_at'])<=1,'proof has a fresh server timestamp');
check(($transients['dayu_fcpx_oauth_proof_'.hash('sha256',str_repeat('a',40))]??null)===$proof,
'transient fallback matches proof across PHP session boundaries');
check(in_array('oauth_proof_written',array_column($GLOBALS['dayu_macos_app_auth']->events,'stage'),true),
'successful proof is visible in existing login diagnostics');
foreach (array('FCPXQwen3ASR','FCPXPython','FCPXSoundEffects','qwenzhiyin','DayuDownie','DayuLightFactory') as $app) {
check(is_array(callback_proof($app)),'existing app callback preserved: '.$app);
}
check(callback_proof('UnknownApp')===null,'unrecognized apps do not receive proof');
check(callback_proof('DayuColor',array(),'foreign.example')===null,'foreign redirect host cannot receive proof');
check(callback_proof('DayuColor',array('action'=>'other_action'))===null,'wrong callback action cannot receive proof');
check(callback_proof('DayuColor',array('fcpxqwen_session'=>'short'))===null,'invalid login session cannot receive proof');
check(callback_proof('DayuColor',array('device_uuid'=>'random-client-id'))===null,'non-hardware UUID cannot receive proof');
check(callback_proof('DayuColor',array(),'dayu.media',false)===null,'browser cookie or redirect alone cannot bypass provider state');
session_destroy();
echo json_encode(array('pass'=>true,'count'=>count($checks),
'scope'=>'Actual scoped theme callback with synthetic OAuth and WordPress services; no live scan or user data.',
'checks'=>$checks),JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE)."\n";
}