This commit is contained in:
2026-03-17 16:55:45 +08:00
parent 2f469d6b60
commit 0a535c3a89
3 changed files with 246 additions and 207 deletions
+12 -8
View File
@@ -57,18 +57,21 @@ class AppConfig
/** /**
* @var array|string[] * @var NoticeConfig|null
*/ */
#[ArrayShape(['token' => 'string', 'secret' => 'string', 'unionId' => 'string'])] public ?NoticeConfig $notice = null;
public array $notice = ['token' => '', 'secret' => '', 'unionId' => ''];
/**
*
*/
public function __construct() public function __construct()
{ {
$this->pay = new PayConfig(); $this->pay = new PayConfig;
$this->pay->wx = new Wx(); $this->pay->wx = new Wx;
$this->pay->qq = new Qq(); $this->pay->qq = new Qq;
$this->pay->ali = new Aliyun(); $this->pay->ali = new Aliyun;
} }
@@ -78,10 +81,11 @@ class AppConfig
*/ */
public static function instance(object $app): static public static function instance(object $app): static
{ {
$model = new static(); $model = new static;
$model->appId = $app->appId; $model->appId = $app->appId;
$model->appSecret = $app->appSecret; $model->appSecret = $app->appSecret;
$model->type = $app->type; $model->type = $app->type;
$model->notice = NoticeConfig::parse($app->notice);
PayConfig::parse($app->pay, $model->pay); PayConfig::parse($app->pay, $model->pay);
+35
View File
@@ -0,0 +1,35 @@
<?php
namespace wchat\common;
class NoticeConfig
{
public string $token;
public string $encodingAESKey;
public string $unionId;
/**
* @param string $token
* @param string $encodingAESKey
* @param string $unionId
*/
public function __construct(string $token, string $encodingAESKey, string $unionId)
{
$this->token = $token;
$this->encodingAESKey = $encodingAESKey;
$this->unionId = $unionId;
}
/**
* @param array $map
* @return static
*/
public static function parse(array $map): static
{
return new static($map['token'], $map['secret'], $map['unionId'] ?? '');
}
}
+1 -1
View File
@@ -26,7 +26,7 @@ class SmallProgram extends Multiprogramming
*/ */
public function decode(string $encrypt, string $signature, string $timestamp, string $nonce, string $msg_signature): XPayGoodsDeliverNotify|bool public function decode(string $encrypt, string $signature, string $timestamp, string $nonce, string $msg_signature): XPayGoodsDeliverNotify|bool
{ {
$WxMsgCrypt = new WxMsgCrypt($this->payConfig->notice['token'], $this->payConfig->notice['secret'], $this->payConfig->appId); $WxMsgCrypt = new WxMsgCrypt($this->payConfig->notice->token, $this->payConfig->notice->encodingAESKey, $this->payConfig->appId);
if (!$WxMsgCrypt->verifySignature($timestamp, $nonce, $encrypt, $msg_signature)) { if (!$WxMsgCrypt->verifySignature($timestamp, $nonce, $encrypt, $msg_signature)) {
return false; return false;
} else { } else {