This commit is contained in:
xl
2023-11-14 12:39:28 +08:00
parent c3326a9b5a
commit f92fdab692
15 changed files with 245 additions and 272 deletions
+3 -3
View File
@@ -139,7 +139,7 @@ abstract class Subject extends Multiprogramming
*/
public function sendTemplate(): Result
{
$access_token = $this->config->getAccessToken();
$access_token = $this->payConfig->getAccessToken();
if (empty($access_token)) {
throw new \Exception('request access_token con\'t null.');
}
@@ -163,8 +163,8 @@ abstract class Subject extends Multiprogramming
$client = new Client($this->getHost(), 443, true);
$client->withHeader(['Content-Type' => 'application/json; charset=utf-8']);
$proxyHost = $this->getConfig()->getProxyHost();
$proxyPort = $this->getConfig()->getProxyPort();
$proxyHost = $this->payConfig->getProxyHost();
$proxyPort = $this->payConfig->getProxyPort();
if (!empty($proxyHost) && $proxyPort > 0) {
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
}
+4 -4
View File
@@ -71,7 +71,7 @@ abstract class Template extends Multiprogramming
/**
* @param $index
* @param $context
* @param $color
* @param string $color
*/
public function replaceKeyword($index, $context, string $color = '')
{
@@ -112,7 +112,7 @@ abstract class Template extends Multiprogramming
*/
public function sendTemplate(): Result
{
$access_token = $this->config->getAccessToken();
$access_token = $this->payConfig->getAccessToken();
if (empty($access_token)) {
throw new \Exception('request access_token con\'t null.');
}
@@ -134,8 +134,8 @@ abstract class Template extends Multiprogramming
$client = new Client($this->getHost(), 443, true);
$client->withHeader(['Content-Type' => 'application/json; charset=utf-8']);
$proxyHost = $this->getConfig()->getProxyHost();
$proxyPort = $this->getConfig()->getProxyPort();
$proxyHost = $this->payConfig->getProxyHost();
$proxyPort = $this->payConfig->getProxyPort();
if (!empty($proxyHost) && $proxyPort > 0) {
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
}
+22 -20
View File
@@ -18,9 +18,6 @@ abstract class Multiprogramming implements Progaram
protected string $errorMsg = '';
protected string $host = 'api.weixin.qq.com';
/**
* @var AppConfig
*/
@@ -87,49 +84,54 @@ abstract class Multiprogramming implements Progaram
/**
* @param string $host
* @param string $requestUrl
* @param mixed $body
* @param string $contentType
* @return Result
*/
protected function post(string $requestUrl, mixed $body, string $contentType = 'application/application'): Result
protected function post(string $host, string $requestUrl, mixed $body, string $contentType = 'application/application'): Result
{
return $this->request('post', $requestUrl, $body, $contentType);
return $this->request($host, 'post', $requestUrl, $body, $contentType);
}
/**
* @param string $host
* @param string $requestUrl
* @param mixed $body
* @param string $contentType
* @return Result
*/
protected function get(string $host, string $requestUrl, mixed $body, string $contentType = 'application/application'): Result
{
return $this->request($host, 'get', $requestUrl, $body, $contentType);
}
/**
* @param string $host
* @param string $requestUrl
* @param mixed $body
* @return Result
*/
protected function get(string $requestUrl, mixed $body, string $contentType = 'application/application'): Result
protected function upload(string $host, string $requestUrl, mixed $body): Result
{
return $this->request('get', $requestUrl, $body, $contentType);
}
/**
* @param string $requestUrl
* @param mixed $body
* @return Result
*/
protected function upload(string $requestUrl, mixed $body): Result
{
return $this->request('upload', $requestUrl, $body);
return $this->request($host, 'upload', $requestUrl, $body);
}
/**
* @param string $host
* @param string $method
* @param string $requestUrl
* @param $body
* @param string $contentType
* @return Result
*/
private function request(string $method, string $requestUrl, $body, string $contentType = 'application/application'): Result
private function request(string $host, string $method, string $requestUrl, $body, string $contentType = 'application/application'): Result
{
$client = new Client($this->host, 443, true);
$client = new Client($host, 80, true);
$proxyHost = $this->payConfig->getProxyHost();
$proxyPort = $this->payConfig->getProxyPort();
if (!empty($proxyHost) && $proxyPort > 0) {
+18 -1
View File
@@ -25,7 +25,24 @@ class Account extends SmallProgram
$param['js_code'] = $code;
$param['grant_type'] = 'authorization_code';
return $this->get('/sns/jscode2session', $param);
return $this->get('api.q.qq.com', '/sns/jscode2session', $param);
}
/**
* @param string $code
* @return Result
*/
public function appLogin(string $code): Result
{
$param['appid'] = $this->payConfig->appId;
$param['secret'] = $this->payConfig->appSecret;
$param['js_code'] = $code;
$param['grant_type'] = 'authorization_code';
$this->host = 'graph.qq.com';
return $this->get('api.q.qq.com', '/user/get_user_info', $param);
}
}
+1 -1
View File
@@ -51,7 +51,7 @@ class Recharge extends SmallProgram
$this->orderNo = $orderNo;
$this->data['openid'] = $openId;
return $this->post($this->uniformer, $this->builder(), 'application/xml');
return $this->post('api.q.qq.com', $this->uniformer, $this->builder(), 'application/xml');
}
+7 -8
View File
@@ -299,11 +299,10 @@ class Redhat extends SmallProgram
{
$client = new Client('api.qpay.qq.com', 443, true);
$client->withHeader(['Content-Type' => 'application/x-www-form-urlencoded']);
$client->withSslKeyFile($this->payConfig->getSslKey());
$client->withSslCertFile($this->payConfig->getSslCert());
$client->withCa($this->payConfig->getSslCa());
$proxyHost = $this->getConfig()->getProxyHost();
$proxyPort = $this->getConfig()->getProxyPort();
$client->withSslKeyFile($this->payConfig->pay->wx->mchKey);
$client->withSslCertFile($this->payConfig->pay->wx->mchCert);
$proxyHost = $this->payConfig->getProxyHost();
$proxyPort = $this->payConfig->getProxyPort();
if (!empty($proxyHost) && $proxyPort > 0) {
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
}
@@ -332,15 +331,15 @@ class Redhat extends SmallProgram
public function searchByOrderNo($listid, $orderNo = null): Result
{
$requestParam['nonce_str'] = Help::random(31);
$requestParam['mch_id'] = $this->payConfig->getMchId();
$requestParam['mch_id'] = $this->payConfig->pay->wx->mchId;
$requestParam['listid'] = $listid;
if (!empty($orderNo)) {
$requestParam['mch_billno'] = $orderNo;
}
$requestParam['sign'] = $this->builderSign($requestParam);
$client = new Client('qpay.qq.com', 443, true);
$proxyHost = $this->getConfig()->getProxyHost();
$proxyPort = $this->getConfig()->getProxyPort();
$proxyHost = $this->payConfig->getProxyHost();
$proxyPort = $this->payConfig->getProxyPort();
if (!empty($proxyHost) && $proxyPort > 0) {
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
}
+3 -3
View File
@@ -35,7 +35,7 @@ class SecCheck extends SmallProgram
'form-data[filename]' => $path,
'form-data[content-type]' => $real_path->getMimeType()
];
return $this->upload($path, $data);
return $this->upload('api.q.qq.com', $this->_url, $data);
}
@@ -48,9 +48,9 @@ class SecCheck extends SmallProgram
if (empty($content)) {
return $this->sendError('文件不存在', 404);
}
$url = '/' . ltrim($this->_url, '/') . $this->payConfig->getAccessToken();
$url = '/' . ltrim($this->_msgUrl, '/') . $this->payConfig->getAccessToken();
return $this->post($url, ['appid' => $this->payConfig->appId, 'content' => $content]);
return $this->post('api.q.qq.com', $url, ['appid' => $this->payConfig->appId, 'content' => $content]);
}
}
+1 -1
View File
@@ -20,7 +20,7 @@ class Token extends SmallProgram
'appid' => $this->payConfig->appId,
'secret' => $this->payConfig->appSecret
];
return $this->get('/api/getToken', $query);
return $this->get('api.q.qq.com', '/api/getToken', $query);
}
}
+9 -36
View File
@@ -9,7 +9,6 @@
namespace wchat\wx;
use Exception;
use wchat\common\Decode;
use wchat\common\Result;
class Account extends SmallProgram
@@ -26,7 +25,7 @@ class Account extends SmallProgram
$param['js_code'] = $code;
$param['grant_type'] = 'authorization_code';
return $this->get('/sns/jscode2session', $param);
return $this->get('api.weixin.qq.com', '/sns/jscode2session', $param);
}
/**
@@ -40,7 +39,7 @@ class Account extends SmallProgram
$param['js_code'] = $code;
$param['grant_type'] = 'authorization_code';
return $this->get('/sns/oauth2/access_token', $param);
return $this->get('api.weixin.qq.com', '/sns/oauth2/access_token', $param);
}
/**
@@ -55,7 +54,7 @@ class Account extends SmallProgram
'openid' => $openid,
'lang' => 'zh_CN'
];
return $this->get('/cgi-bin/user/info', $query);
return $this->get('api.weixin.qq.com', '/cgi-bin/user/info', $query);
}
/**
@@ -69,33 +68,7 @@ class Account extends SmallProgram
'access_token' => $this->payConfig->getAccessToken(),
'openid' => $openid,
];
return $this->get('/sns/userinfo', $query);
}
/**
* @param $encryptedData
* @param $iv
* @param $sessionKey
* @param bool $asArray
* @return object|array
* @throws
*
* * <li>-41001: encodingAesKey 非法</li>
* <li>-41003: aes 解密失败</li>
* <li>-41004: 解密后得到的buffer非法</li>
* <li>-41005: base64加密失败</li>
* <li>-41016: base64解密失败</li>
*/
public function decode($encryptedData, $iv, $sessionKey, bool $asArray = false): object|array
{
$decode = new Decode();
$decode->setSessionKey($sessionKey);
$decode->setEncryptedData($encryptedData);
$decode->setAppId($this->payConfig->getAppid());
$decode->setIv($iv);
return $decode->decode($asArray);
return $this->get('api.weixin.qq.com', '/sns/userinfo', $query);
}
@@ -111,7 +84,7 @@ class Account extends SmallProgram
$sendBody['path'] = $path;
$sendBody['width'] = $width;
return $this->get($url . $this->payConfig->getAccessToken(), $sendBody);
return $this->get('api.weixin.qq.com', $url . $this->payConfig->getAccessToken(), $sendBody);
}
@@ -129,11 +102,11 @@ class Account extends SmallProgram
$sendBody['width'] = $width;
$sendBody['auto_color'] = $auto_color;
$sendBody['is_hyaline'] = $is_hyaline;
$url = 'wxa/getwxacode?access_token=' . $this->getConfig()->getAccessToken();
$url = 'wxa/getwxacode?access_token=' . $this->payConfig->getAccessToken();
if ($auto_color) {
$sendBody['line_color'] = $line_color;
}
return $this->get($url . $this->payConfig->getAccessToken(), $sendBody);
return $this->get('api.weixin.qq.com', $url . $this->payConfig->getAccessToken(), $sendBody);
}
@@ -152,11 +125,11 @@ class Account extends SmallProgram
$sendBody['width'] = $width;
$sendBody['auto_color'] = $auto_color;
$sendBody['is_hyaline'] = $is_hyaline;
$url = 'wxa/getwxacodeunlimit?access_token=' . $this->getConfig()->getAccessToken();
$url = 'wxa/getwxacodeunlimit?access_token=' . $this->payConfig->getAccessToken();
if ($auto_color) {
$sendBody['line_color'] = $line_color;
}
return $this->get($url . $this->payConfig->getAccessToken(), $sendBody);
return $this->get('api.weixin.qq.com', $url . $this->payConfig->getAccessToken(), $sendBody);
}
}
+5 -5
View File
@@ -225,15 +225,15 @@ class Message extends SmallProgram
}
/**
* @param $filePath
* @param $type
* @param string $filePath
* @param string $type
* @param bool $isPermanent
* @param string $title
* @param string $introduction
* @return mixed
* @throws Exception
*/
public function upload($filePath, $type, bool $isPermanent = false, string $title = '', string $introduction = ''): Result
public function uploadFile(string $filePath, string $type, bool $isPermanent = false, string $title = '', string $introduction = ''): Result
{
if (!file_exists($filePath)) {
throw new Exception('文件不存在');
@@ -253,7 +253,7 @@ class Message extends SmallProgram
if ($isPermanent && $mime == 'video/mp3') {
$data = ['media' => $real_path, 'description[title]' => $title, 'description[introduction]' => $introduction];
}
return $this->post($url, $data);
return $this->post('api.weixin.qq.com', $url, $data);
}
@@ -273,6 +273,6 @@ class Message extends SmallProgram
private function sendKefuMsg()
{
$url = '/cgi-bin/message/custom/send?access_token=' . $this->payConfig->getAccessToken();
return $this->post($url, $this->msgData);
return $this->post('api.weixin.qq.com', $url, $this->msgData);
}
}
+1 -1
View File
@@ -143,6 +143,6 @@ class PublicTemplate extends SmallProgram
if (!empty($this->miniprogram)) {
$default['miniprogram'] = $this->miniprogram;
}
return $this->post($url, $default);
return $this->post('api.weixin.qq.com', $url, $default);
}
}
+3 -3
View File
@@ -31,7 +31,7 @@ class SecCheck extends SmallProgram
}
$access_token = $this->payConfig->getAccessToken();
return $this->upload($this->_url . '?access_token=' . $access_token, [
return $this->upload('api.weixin.qq.com', $this->_url . '?access_token=' . $access_token, [
'media' => new \CURLFile($path)
]);
}
@@ -50,7 +50,7 @@ class SecCheck extends SmallProgram
}
$requestUrl = $this->_mediaCheckAsync . $this->payConfig->getAccessToken();
return $this->post($requestUrl, ['media_url' => $url, 'media_type' => $type]);
return $this->post('api.weixin.qq.com', $requestUrl, ['media_url' => $url, 'media_type' => $type]);
}
@@ -75,7 +75,7 @@ class SecCheck extends SmallProgram
}
$requestUrl = $this->_msgUrl . $this->payConfig->getAccessToken();
return $this->post($requestUrl, ['content' => $content]);
return $this->post('api.weixin.qq.com', $requestUrl, ['content' => $content]);
}
}
+1 -1
View File
@@ -23,7 +23,7 @@ class Token extends SmallProgram
$query['appid'] = $this->payConfig->appId;
$query['secret'] = $this->payConfig->appSecret;
}
return $this->get('cgi-bin/token', $query);
return $this->get('api.weixin.qq.com', 'cgi-bin/token', $query);
}
+1 -2
View File
@@ -34,9 +34,8 @@ class WxV3Payment extends SmallProgram
$client->close();
$json = json_decode($client->getBody(), TRUE);
var_dump($client->getBody());
if (!isset($json['prepay_id'])) {
throw new Exception('微信支付调用失败');
throw new Exception('微信支付调用失败: ' . $client->getBody());
}
return $this->createResponse($json, $body);
+1 -18
View File
@@ -12,28 +12,11 @@ use wchat\common\Help;
*/
const BLOCK_SIZE = 16;
/**
* Bytes length of the AES secret key.
*/
const KEY_LENGTH_BYTE = 32;
/**
* Bytes Length of the authentication tag in AEAD cipher mode
* @deprecated 1.0 - As of the OpenSSL described, the `auth_tag` length may be one of 16, 15, 14, 13, 12, 8 or 4.
* Keep it only compatible for the samples on the official documentation.
*/
const AUTH_TAG_LENGTH_BYTE = 16;
/**
* The `aes-256-gcm` algorithm string
*/
const ALGO_AES_256_GCM = 'aes-256-gcm';
/**
* The `aes-256-ecb` algorithm string
*/
const ALGO_AES_256_ECB = 'aes-256-ecb';
trait WxV3PaymentTait
{
@@ -111,7 +94,7 @@ trait WxV3PaymentTait
{
$payConfig = $this->getPayConfig();
$mch_private_key = openssl_get_privatekey($payConfig->pay->wx->mchKey);
$mch_private_key = openssl_get_privatekey(file_get_contents($payConfig->pay->wx->mchKey));
openssl_sign($body, $raw_sign, $mch_private_key, 'sha256WithRSAEncryption');
return base64_encode($raw_sign);