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
+209 -205
View File
@@ -11,250 +11,254 @@ class AppConfig
{ {
const int TYPE_WCHAT_PROJECT = 0; const int TYPE_WCHAT_PROJECT = 0;
const int TYPE_ALI_GAME_OR_APPLET = 3; const int TYPE_ALI_GAME_OR_APPLET = 3;
const int TYPE_QQ_GAME_OR_APPLET = 1; const int TYPE_QQ_GAME_OR_APPLET = 1;
const int TYPE_APP_PROJECT = 2; const int TYPE_APP_PROJECT = 2;
/** /**
* @var string * @var string
*/ */
public string $appId = ''; public string $appId = '';
/** /**
* @var string * @var string
*/ */
private string $host = ''; private string $host = '';
/** /**
* @var string * @var string
*/ */
public string $appSecret = ''; public string $appSecret = '';
/** /**
* @var PayConfig * @var PayConfig
*/ */
public PayConfig $pay; public PayConfig $pay;
private string $proxyHost = ''; private string $proxyHost = '';
private int $proxyPort = 0; private int $proxyPort = 0;
private string $notifyUrl = ''; private string $notifyUrl = '';
private string $body = ''; private string $body = '';
private string $currency = 'CNY'; private string $currency = 'CNY';
private string $remoteIp = ''; private string $remoteIp = '';
private string $accessToken = ''; private string $accessToken = '';
private string $tradeType = 'JSAPI'; private string $tradeType = 'JSAPI';
private string $signType = 'MD5'; private string $signType = 'MD5';
/** /**
* @var int * @var int
*/ */
public int $type; public int $type;
/** /**
* @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()
{ /**
$this->pay = new PayConfig(); *
$this->pay->wx = new Wx(); */
$this->pay->qq = new Qq(); public function __construct()
$this->pay->ali = new Aliyun(); {
} $this->pay = new PayConfig;
$this->pay->wx = new Wx;
$this->pay->qq = new Qq;
$this->pay->ali = new Aliyun;
}
/** /**
* @param object $app * @param object $app
* @return static * @return static
*/ */
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);
return $model; return $model;
} }
/** /**
* @return bool * @return bool
*/ */
public function typeIsApp(): bool public function typeIsApp(): bool
{ {
return $this->type === self::TYPE_APP_PROJECT; return $this->type === self::TYPE_APP_PROJECT;
} }
/** /**
* @return string * @return string
*/ */
public function getProxyHost(): string public function getProxyHost(): string
{ {
return $this->proxyHost; return $this->proxyHost;
} }
/** /**
* @param string $proxyHost * @param string $proxyHost
*/ */
public function setProxyHost(string $proxyHost): void public function setProxyHost(string $proxyHost): void
{ {
$this->proxyHost = $proxyHost; $this->proxyHost = $proxyHost;
} }
/** /**
* @return int * @return int
*/ */
public function getProxyPort(): int public function getProxyPort(): int
{ {
return $this->proxyPort; return $this->proxyPort;
} }
/** /**
* @param int $proxyPort * @param int $proxyPort
*/ */
public function setProxyPort(int $proxyPort): void public function setProxyPort(int $proxyPort): void
{ {
$this->proxyPort = $proxyPort; $this->proxyPort = $proxyPort;
} }
/** /**
* @return string * @return string
*/ */
public function getNotifyUrl(): string public function getNotifyUrl(): string
{ {
return $this->notifyUrl; return $this->notifyUrl;
} }
/** /**
* @param string $notifyUrl * @param string $notifyUrl
*/ */
public function setNotifyUrl(string $notifyUrl): void public function setNotifyUrl(string $notifyUrl): void
{ {
$this->notifyUrl = $notifyUrl; $this->notifyUrl = $notifyUrl;
} }
/** /**
* @return string * @return string
*/ */
public function getBody(): string public function getBody(): string
{ {
return $this->body; return $this->body;
} }
/** /**
* @param string $body * @param string $body
*/ */
public function setBody(string $body): void public function setBody(string $body): void
{ {
$this->body = $body; $this->body = $body;
} }
/** /**
* @return string * @return string
*/ */
public function getCurrency(): string public function getCurrency(): string
{ {
return $this->currency; return $this->currency;
} }
/** /**
* @param string $currency * @param string $currency
*/ */
public function setCurrency(string $currency): void public function setCurrency(string $currency): void
{ {
$this->currency = $currency; $this->currency = $currency;
} }
/** /**
* @return string * @return string
*/ */
public function getRemoteIp(): string public function getRemoteIp(): string
{ {
return $this->remoteIp; return $this->remoteIp;
} }
/** /**
* @param string $remoteIp * @param string $remoteIp
*/ */
public function setRemoteIp(string $remoteIp): void public function setRemoteIp(string $remoteIp): void
{ {
$this->remoteIp = $remoteIp; $this->remoteIp = $remoteIp;
} }
/** /**
* @return string * @return string
*/ */
public function getAccessToken(): string public function getAccessToken(): string
{ {
return $this->accessToken; return $this->accessToken;
} }
/** /**
* @param string $accessToken * @param string $accessToken
*/ */
public function setAccessToken(string $accessToken): void public function setAccessToken(string $accessToken): void
{ {
$this->accessToken = $accessToken; $this->accessToken = $accessToken;
} }
/** /**
* @return string * @return string
*/ */
public function getTradeType(): string public function getTradeType(): string
{ {
return $this->tradeType; return $this->tradeType;
} }
/** /**
* @param string $tradeType * @param string $tradeType
*/ */
public function setTradeType(string $tradeType): void public function setTradeType(string $tradeType): void
{ {
$this->tradeType = $tradeType; $this->tradeType = $tradeType;
} }
/** /**
* @return string * @return string
*/ */
public function getSignType(): string public function getSignType(): string
{ {
return $this->signType; return $this->signType;
} }
/** /**
* @param string $signType * @param string $signType
*/ */
public function setSignType(string $signType): void public function setSignType(string $signType): void
{ {
$this->signType = $signType; $this->signType = $signType;
} }
/** /**
* @return string * @return string
*/ */
public function getHost(): string public function getHost(): string
{ {
return $this->host; return $this->host;
} }
/** /**
* @param string $host * @param string $host
*/ */
public function setHost(string $host): void public function setHost(string $host): void
{ {
$this->host = $host; $this->host = $host;
} }
} }
+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 {