Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 693ec4fa65 | |||
| 389f5261c7 | |||
| cf03ebd6dc | |||
| e0d1811a00 | |||
| 1a78bdb173 | |||
| c5f8b19a83 | |||
| 227ff1c166 | |||
| b8960deda5 | |||
| ac70bd3df5 | |||
| 9264f05a49 | |||
| a2dc66ec84 | |||
| d0a6787b85 | |||
| 7f2bdbdb4f | |||
| 459d298983 | |||
| a876b780f5 | |||
| 885c902be8 | |||
| 43f504b2ad | |||
| dbdae7c6c5 | |||
| b87232bbc0 | |||
| d9528679ff | |||
| 09544ee4a2 | |||
| a7c6939a9f | |||
| 0578ba384b | |||
| 7abbaaca46 | |||
| d574ce2c42 | |||
| 2275ed92d1 | |||
| 48467b88ce | |||
| e87728266b | |||
| ae67dce77b | |||
| 2ff7ceb66b |
@@ -1,3 +1,4 @@
|
||||
/.idea/php.xml
|
||||
vendor/
|
||||
composer.lock
|
||||
.idea/*
|
||||
+1
-1
@@ -21,8 +21,8 @@
|
||||
},
|
||||
"require": {
|
||||
"php": ">= 8.0",
|
||||
"game-worker/kiri-client": "~v2.6",
|
||||
"game-worker/kiri-container": "~v1.9",
|
||||
"game-worker/kiri-client": "~v2.8",
|
||||
"psr/container": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
|
||||
@@ -162,11 +162,18 @@ abstract class Subject extends Multiprogramming
|
||||
|
||||
$client = new Client($this->getHost(), 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json; charset=utf-8']);
|
||||
$client->post($this->getUrl() . '?access_token=' . $access_token, $params);
|
||||
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
|
||||
$client->post($this->getUrl() . '?access_token=' . $access_token, $params);
|
||||
$client->close();
|
||||
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$body = json_decode($client->getBody(), true);
|
||||
if (isset($body['errcode']) && $body['errcode'] != 0) {
|
||||
|
||||
@@ -133,11 +133,18 @@ abstract class Template extends Multiprogramming
|
||||
|
||||
$client = new Client($this->getHost(), 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json; charset=utf-8']);
|
||||
$client->post($this->getUrl() . '?access_token=' . $access_token, $params);
|
||||
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
|
||||
$client->post($this->getUrl() . '?access_token=' . $access_token, $params);
|
||||
$client->close();
|
||||
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$body = json_decode($client->getBody(), true);
|
||||
if (isset($body['errcode']) && $body['errcode'] != 0) {
|
||||
|
||||
+620
-547
File diff suppressed because it is too large
Load Diff
@@ -57,7 +57,7 @@ class Result
|
||||
public static function init(Client $client): static
|
||||
{
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$body = json_decode($client->getBody(), true);
|
||||
if (isset($body['errcode']) && $body['errcode'] != 0) {
|
||||
|
||||
@@ -27,7 +27,14 @@ class Account extends SmallProgram
|
||||
|
||||
$client = new Client('api.q.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
$client->get('sns/jscode2session', $param);
|
||||
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
|
||||
$client->get('sns/jscode2session', $param);
|
||||
$client->close();
|
||||
|
||||
return Result::init($client);
|
||||
|
||||
@@ -52,11 +52,18 @@ class Recharge extends SmallProgram
|
||||
$client = new Client('qpay.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/xml']);
|
||||
$client->withBody($this->builder());
|
||||
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
|
||||
$client->post($this->uniformer);
|
||||
$client->close();
|
||||
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
|
||||
$data = Help::toArray($client->getBody());
|
||||
|
||||
+23
-145
@@ -11,12 +11,9 @@ class Redhat extends SmallProgram
|
||||
{
|
||||
|
||||
private string $charset = 'UTF8';
|
||||
private string $nonce_str = '';
|
||||
private string $sign = '';
|
||||
private string $mch_billno = '';
|
||||
private string $mch_id = '';
|
||||
private string $mch_name = '';
|
||||
private string $qqappid = '';
|
||||
private string $re_openid = '';
|
||||
private string $total_amount = '';
|
||||
private string $total_num = '';
|
||||
@@ -24,12 +21,9 @@ class Redhat extends SmallProgram
|
||||
private string $act_name = '';
|
||||
private string $icon_id = '';
|
||||
private string $banner_id = '';
|
||||
private string $notify_url = '';
|
||||
private string $not_send_msg = '';
|
||||
private string $min_value = '';
|
||||
private string $max_value = '';
|
||||
private string $key = '';
|
||||
private string $signType = '';
|
||||
|
||||
|
||||
private string $sendUrl = '/cgi-bin/hongbao/qpay_hb_mch_send.cgi';
|
||||
@@ -51,22 +45,6 @@ class Redhat extends SmallProgram
|
||||
$this->charset = $charset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getNonceStr(): string
|
||||
{
|
||||
return $this->nonce_str;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $nonce_str
|
||||
*/
|
||||
public function setNonceStr(string $nonce_str): void
|
||||
{
|
||||
$this->nonce_str = $nonce_str;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -99,22 +77,6 @@ class Redhat extends SmallProgram
|
||||
$this->mch_billno = $mch_billno;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMchId(): string
|
||||
{
|
||||
return $this->mch_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $mch_id
|
||||
*/
|
||||
public function setMchId(string $mch_id): void
|
||||
{
|
||||
$this->mch_id = $mch_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -131,21 +93,6 @@ class Redhat extends SmallProgram
|
||||
$this->mch_name = $mch_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getQqappid(): string
|
||||
{
|
||||
return $this->qqappid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $qqappid
|
||||
*/
|
||||
public function setQqappid(string $qqappid): void
|
||||
{
|
||||
$this->qqappid = $qqappid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
@@ -259,22 +206,6 @@ class Redhat extends SmallProgram
|
||||
$this->banner_id = $banner_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getNotifyUrl(): string
|
||||
{
|
||||
return $this->notify_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $notify_url
|
||||
*/
|
||||
public function setNotifyUrl(string $notify_url): void
|
||||
{
|
||||
$this->notify_url = $notify_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -323,84 +254,20 @@ class Redhat extends SmallProgram
|
||||
$this->max_value = $max_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getKey(): string
|
||||
{
|
||||
return $this->key;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
*/
|
||||
public function setKey(string $key): void
|
||||
{
|
||||
$this->key = $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSignType(): string
|
||||
{
|
||||
return $this->signType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $signType
|
||||
*/
|
||||
public function setSignType(string $signType): void
|
||||
{
|
||||
$this->signType = $signType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSendUrl(): string
|
||||
{
|
||||
return $this->sendUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sendUrl
|
||||
*/
|
||||
public function setSendUrl(string $sendUrl): void
|
||||
{
|
||||
$this->sendUrl = $sendUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSearchUrl(): string
|
||||
{
|
||||
return $this->searchUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $searchUrl
|
||||
*/
|
||||
public function setSearchUrl(string $searchUrl): void
|
||||
{
|
||||
$this->searchUrl = $searchUrl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* 构建请求参数
|
||||
*/
|
||||
private function generate(): array
|
||||
public function generate(): array
|
||||
{
|
||||
$requestParam = [];
|
||||
$requestParam['charset'] = $this->getCharset();
|
||||
$requestParam['nonce_str'] = $this->getNonceStr();
|
||||
$requestParam['nonce_str'] = Help::random(30);
|
||||
$requestParam['mch_billno'] = $this->getMchBillno();
|
||||
$requestParam['mch_id'] = $this->getMchId();
|
||||
$requestParam['mch_id'] = $this->config->getMchId();
|
||||
$requestParam['mch_name'] = $this->getMchName();
|
||||
$requestParam['qqappid'] = $this->getQqappid();
|
||||
$requestParam['qqappid'] = $this->config->getAppid();
|
||||
$requestParam['re_openid'] = $this->getReOpenid();
|
||||
$requestParam['total_amount'] = $this->getTotalAmount() * 100;
|
||||
$requestParam['min_value'] = $this->getMinValue() * 100;
|
||||
@@ -409,7 +276,7 @@ class Redhat extends SmallProgram
|
||||
$requestParam['wishing'] = $this->getWishing();
|
||||
$requestParam['act_name'] = $this->getActName();
|
||||
$requestParam['icon_id'] = $this->getIconId();
|
||||
$requestParam['notify_url'] = $this->getNotifyUrl();
|
||||
$requestParam['notify_url'] = $this->config->getNotifyUrl();
|
||||
|
||||
$requestParam['sign'] = $this->builderSign($requestParam);
|
||||
|
||||
@@ -423,7 +290,7 @@ class Redhat extends SmallProgram
|
||||
*/
|
||||
private function builderSign($requestParam): string
|
||||
{
|
||||
return Help::sign($requestParam, $this->getKey(), $this->getSignType());
|
||||
return Help::sign($requestParam, $this->config->getKey(), $this->config->getSignType());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -432,13 +299,19 @@ class Redhat extends SmallProgram
|
||||
public function redEnvelopes(): Result
|
||||
{
|
||||
$client = new Client('api.qpay.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
$client->withHeader(['Content-Type' => 'application/x-www-form-urlencoded']);
|
||||
$client->withSslKeyFile($this->config->getSslKey());
|
||||
$client->withSslCertFile($this->config->getSslCert());
|
||||
$client->post($this->sendUrl, $this->generate());
|
||||
$client->withCa($this->config->getSslCa());
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
$client->post($this->sendUrl, http_build_query($this->generate()));
|
||||
$client->close();
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$json = json_decode($client->getBody(), true);
|
||||
if (isset($json['return_code']) && $json['return_code'] != 'SUCCESS') {
|
||||
@@ -459,8 +332,8 @@ class Redhat extends SmallProgram
|
||||
*/
|
||||
public function searchByOrderNo($listid, $orderNo = null): Result
|
||||
{
|
||||
$requestParam['nonce_str'] = $this->getNonceStr();
|
||||
$requestParam['mch_id'] = $this->getMchId();
|
||||
$requestParam['nonce_str'] = Help::random(31);
|
||||
$requestParam['mch_id'] = $this->config->getMchId();
|
||||
$requestParam['listid'] = $listid;
|
||||
if (!empty($orderNo)) {
|
||||
$requestParam['mch_billno'] = $orderNo;
|
||||
@@ -468,10 +341,15 @@ class Redhat extends SmallProgram
|
||||
$requestParam['sign'] = $this->builderSign($requestParam);
|
||||
$client = new Client('qpay.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
$client->post($this->searchUrl, $requestParam);
|
||||
$client->close();
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$json = json_decode($client->getBody(), true);
|
||||
if (isset($json['result']) && $json['result'] != 'SUCCESS') {
|
||||
|
||||
+12
-2
@@ -37,10 +37,15 @@ class SecCheck extends SmallProgram
|
||||
];
|
||||
$client = new Client('api.q.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'multipart/form-data']);
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
$client->upload($path, $data);
|
||||
$client->close();
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$body = json_decode($client->getBody(), true);
|
||||
if (isset($body['errCode']) && $body['errCode'] != 0) {
|
||||
@@ -64,11 +69,16 @@ class SecCheck extends SmallProgram
|
||||
|
||||
$client = new Client('api.q.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
$client->post($url, ['appid' => $this->config->getAppid(), 'content' => $content]);
|
||||
$client->close();
|
||||
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$body = json_decode($client->getBody(), true);
|
||||
if (isset($body['errCode']) && $body['errCode'] != 0) {
|
||||
|
||||
+6
-1
@@ -22,10 +22,15 @@ class Token extends SmallProgram
|
||||
];
|
||||
$client = new Client('api.q.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
$client->get('/api/getToken', $query);
|
||||
$client->close();
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$body = json_decode($client->getBody(), true);
|
||||
if (isset($body['errcode']) && $body['errcode'] != 0) {
|
||||
|
||||
@@ -91,10 +91,17 @@ class Cash_Bonus extends SmallProgram
|
||||
$client->withSslCertFile($this->getConfig()->getSslCert());
|
||||
$client->withSslKeyFile($this->getConfig()->getSslKey());
|
||||
$client->withCa($this->getConfig()->getSslCa());
|
||||
$client->post($this->_cash, $this->orderConfig($mch_billno, $openId, $price));
|
||||
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
|
||||
$client->post($this->_cash, $this->orderConfig($mch_billno, $openId, $price));
|
||||
$client->close();
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$json = json_decode($client->getBody(), true);
|
||||
|
||||
|
||||
@@ -77,10 +77,17 @@ class Enterprise_payment extends SmallProgram
|
||||
$client->withSslCertFile($this->getConfig()->getSslCert());
|
||||
$client->withSslKeyFile($this->getConfig()->getSslKey());
|
||||
$client->withCa($this->getConfig()->getSslCa());
|
||||
$client->post($this->_cash, $this->orderConfig($mch_billno, $openId, $price));
|
||||
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
|
||||
$client->post($this->_cash, $this->orderConfig($mch_billno, $openId, $price));
|
||||
$client->close();
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$json = json_decode($client->getBody(), true);
|
||||
if (isset($json['return_code']) && $json['return_code'] != 'SUCCESS') {
|
||||
|
||||
+17
-5
@@ -30,11 +30,14 @@ class Account extends SmallProgram
|
||||
|
||||
$client = new Client('api.weixin.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
if (!empty($this->getConfig()->getProxyHost()) && $this->getConfig()->getProxyPort() > 0) {
|
||||
$client->withProxyHost("192.168.0.57")->withProxyPort(12286);
|
||||
}
|
||||
$client->get('sns/jscode2session', $param);
|
||||
$client->close();
|
||||
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$body = json_decode($client->getBody(), true);
|
||||
if (isset($body['errcode']) && $body['errcode'] != 0) {
|
||||
@@ -59,11 +62,14 @@ class Account extends SmallProgram
|
||||
|
||||
$client = new Client('api.weixin.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
if (!empty($this->getConfig()->getProxyHost()) && $this->getConfig()->getProxyPort() > 0) {
|
||||
$client->withProxyHost("192.168.0.57")->withProxyPort(12286);
|
||||
}
|
||||
$client->get('cgi-bin/user/info', $query);
|
||||
$client->close();
|
||||
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$body = json_decode($client->getBody(), true);
|
||||
if (isset($body['errcode']) && $body['errcode'] != 0) {
|
||||
@@ -112,10 +118,16 @@ class Account extends SmallProgram
|
||||
$sendBody['width'] = $width;
|
||||
$client = new Client('api.weixin.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
$client->post($url . $this->getConfig()->getAccessToken(), $sendBody);
|
||||
$client->close();
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$body = json_decode($client->getBody(), true);
|
||||
if (!is_null($body)) {
|
||||
@@ -151,7 +163,7 @@ class Account extends SmallProgram
|
||||
$client->post($url . $this->getConfig()->getAccessToken(), $sendBody);
|
||||
$client->close();
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$body = json_decode($client->getBody(), true);
|
||||
if (!is_null($body)) {
|
||||
@@ -187,7 +199,7 @@ class Account extends SmallProgram
|
||||
$client->post($url . $this->getConfig()->getAccessToken(), $sendBody);
|
||||
$client->close();
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$body = json_decode($client->getBody(), true);
|
||||
if (!is_null($body)) {
|
||||
|
||||
+12
-2
@@ -261,13 +261,18 @@ class Message extends SmallProgram
|
||||
|
||||
$client = new Client('api.weixin.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'multipart/form-data']);
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
$client->post($url, $data);
|
||||
$client->close();
|
||||
|
||||
$this->msgData = [];
|
||||
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$body = json_decode($client->getBody(), true);
|
||||
if (isset($body['errcode']) && $body['errcode'] != 0) {
|
||||
@@ -297,13 +302,18 @@ class Message extends SmallProgram
|
||||
|
||||
$client = new Client('api.weixin.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
$client->post($url, $this->msgData);
|
||||
$client->close();
|
||||
|
||||
$this->msgData = [];
|
||||
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$body = json_decode($client->getBody(), true);
|
||||
if (isset($body['errcode']) && $body['errcode'] != 0) {
|
||||
|
||||
@@ -148,11 +148,16 @@ class PublicTemplate extends SmallProgram
|
||||
|
||||
$client = new Client('api.weixin.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
$client->post($url, $default);
|
||||
$client->close();
|
||||
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$body = json_decode($client->getBody(), true);
|
||||
if (isset($body['errcode']) && $body['errcode'] != 0) {
|
||||
|
||||
+18
-3
@@ -36,13 +36,18 @@ class SecCheck extends SmallProgram
|
||||
|
||||
$client = new Client('api.weixin.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'multipart/form-data']);
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
$client->upload($this->_url . '?access_token=' . $access_token, [
|
||||
'media' => new \CURLFile($path)
|
||||
]);
|
||||
$client->close();
|
||||
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$body = json_decode($client->getBody(), true);
|
||||
if (isset($body['errcode']) && $body['errcode'] != 0) {
|
||||
@@ -66,11 +71,16 @@ class SecCheck extends SmallProgram
|
||||
$requestUrl = $this->_mediaCheckAsync . $this->config->getAccessToken();
|
||||
$client = new Client('api.weixin.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
$client->post($requestUrl, ['media_url' => $url, 'media_type' => $type]);
|
||||
$client->close();
|
||||
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$body = json_decode($client->getBody(), true);
|
||||
if (isset($body['errcode']) && $body['errcode'] != 0) {
|
||||
@@ -104,11 +114,16 @@ class SecCheck extends SmallProgram
|
||||
|
||||
$client = new Client('api.weixin.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
$client->post($requestUrl, ['content' => $content]);
|
||||
$client->close();
|
||||
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$body = json_decode($client->getBody(), true);
|
||||
if (isset($body['errcode']) && $body['errcode'] != 0) {
|
||||
|
||||
+6
-1
@@ -22,10 +22,15 @@ class Token extends SmallProgram
|
||||
];
|
||||
$client = new Client('api.weixin.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
$client->get('cgi-bin/token', $query);
|
||||
$client->close();
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$body = json_decode($client->getBody(), true);
|
||||
if (isset($body['errcode']) && $body['errcode'] != 0) {
|
||||
|
||||
@@ -34,12 +34,17 @@ class WxV2AppPayment extends SmallProgram
|
||||
|
||||
$client = new Client('api.mch.weixin.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
$client->withBody($this->sign($body));
|
||||
$client->post($this->uniformed);
|
||||
$client->close();
|
||||
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$data = Help::toArray($client->getBody());
|
||||
if (isset($data['return_code']) && $data['return_code'] != 'SUCCESS') {
|
||||
|
||||
@@ -37,11 +37,16 @@ class WxV2PayJsApi extends SmallProgram
|
||||
$client = new Client('api.mch.weixin.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
$client->withBody($this->sign($body));
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
$client->post($this->uniformed);
|
||||
$client->close();
|
||||
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$data = Help::toArray($client->getBody());
|
||||
if (isset($data['return_code']) && $data['return_code'] != 'SUCCESS') {
|
||||
@@ -83,11 +88,16 @@ class WxV2PayJsApi extends SmallProgram
|
||||
$client = new Client('api.mch.weixin.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
$client->withBody($this->sign($body));
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
$client->post($this->uniformed);
|
||||
$client->close();
|
||||
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$data = Help::toArray($client->getBody());
|
||||
if (isset($data['return_code']) && $data['return_code'] != 'SUCCESS') {
|
||||
@@ -129,11 +139,16 @@ class WxV2PayJsApi extends SmallProgram
|
||||
$client = new Client('api.mch.weixin.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
$client->withBody($this->sign($body));
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
$client->post($this->uniformed);
|
||||
$client->close();
|
||||
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$data = Help::toArray($client->getBody());
|
||||
if (isset($data['return_code']) && $data['return_code'] != 'SUCCESS') {
|
||||
@@ -175,11 +190,16 @@ class WxV2PayJsApi extends SmallProgram
|
||||
$client = new Client('api.mch.weixin.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
$client->withBody($this->sign($body));
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
$client->post($this->uniformed);
|
||||
$client->close();
|
||||
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$data = Help::toArray($client->getBody());
|
||||
if (isset($data['return_code']) && $data['return_code'] != 'SUCCESS') {
|
||||
|
||||
@@ -40,11 +40,16 @@ class WxV2Withdrawal extends SmallProgram
|
||||
$client = new Client('api.mch.weixin.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
$client->withBody($body = Help::toXml($array));
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
$client->post($this->transfers);
|
||||
$client->close();
|
||||
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
|
||||
$data = Help::toArray($client->getBody());
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace wchat\wx\V3;
|
||||
|
||||
use Exception;
|
||||
use JetBrains\PhpStorm\ArrayShape;
|
||||
use Kiri\Client;
|
||||
use Kiri\CurlClient;
|
||||
use wchat\wx\SmallProgram;
|
||||
|
||||
class TransferBatches extends SmallProgram
|
||||
{
|
||||
use WxV3PaymentTait;
|
||||
|
||||
|
||||
/**
|
||||
* @param TransferDetail $detail
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
#[ArrayShape([])]
|
||||
public function request(TransferDetail $detail): array
|
||||
{
|
||||
$body = [];
|
||||
$body['appid'] = $this->getConfig()->getAppid();
|
||||
$body['out_batch_no'] = $detail->out_detail_no;
|
||||
$body["batch_name"] = $this->getConfig()->getBody();
|
||||
$body["body"] = $this->getConfig()->getBody();
|
||||
$body["batch_remark"] = $this->getConfig()->getBody();
|
||||
$body["total_amount"] = $detail->transfer_amount;
|
||||
$body["total_num"] = 1;
|
||||
$body["transfer_detail_list"] = [$detail->toArray()];
|
||||
|
||||
$sign = $this->signature('POST', '/v3/transfer/batches', $json = json_encode($body, JSON_UNESCAPED_UNICODE));
|
||||
|
||||
$client = new Client('api.mch.weixin.qq.com', 443, TRUE);
|
||||
$client->withAddedHeader('Authorization', $sign)->withContentType('application/json')
|
||||
->withAgent('application/json')->withBody($json)->withAddedHeader("Accept", "*/*");
|
||||
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
|
||||
$client->post('/v3/transfer/batches');
|
||||
$client->close();
|
||||
|
||||
$data = json_decode($client->getBody(), TRUE);
|
||||
if (json_last_error() != JSON_ERROR_NONE) {
|
||||
return ['code' => $client->getStatusCode(), 'message' => $client->getBody()];
|
||||
} else {
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,30 +7,38 @@ use JetBrains\PhpStorm\ArrayShape;
|
||||
class TransferDetail
|
||||
{
|
||||
|
||||
public function __construct(
|
||||
public string $out_detail_no,
|
||||
public int|float $transfer_amount,
|
||||
public string $transfer_remark,
|
||||
public string $openid,
|
||||
public string $user_name
|
||||
)
|
||||
{
|
||||
}
|
||||
public function __construct(
|
||||
public string $out_detail_no,
|
||||
public int|float $transfer_amount,
|
||||
public string $transfer_remark,
|
||||
public string $openid,
|
||||
public string $user_name
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
#[ArrayShape(['out_detail_no' => "string", 'transfer_amount' => "float|int", 'transfer_remark' => "string", 'openid' => "string", 'user_name' => "string"])]
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'out_detail_no' => $this->out_detail_no,
|
||||
'transfer_amount' => $this->transfer_amount,
|
||||
'transfer_remark' => $this->transfer_remark,
|
||||
'openid' => $this->openid,
|
||||
'user_name' => $this->user_name,
|
||||
];
|
||||
}
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
#[ArrayShape(['out_detail_no' => "string", 'transfer_amount' => "float|int", 'transfer_remark' => "string", 'openid' => "string", 'user_name' => "string"])]
|
||||
public function toArray(): array
|
||||
{
|
||||
if (empty($this->user_name)) {
|
||||
return [
|
||||
'out_detail_no' => $this->out_detail_no,
|
||||
'transfer_amount' => $this->transfer_amount,
|
||||
'transfer_remark' => $this->transfer_remark,
|
||||
'openid' => $this->openid,
|
||||
];
|
||||
}
|
||||
return [
|
||||
'out_detail_no' => $this->out_detail_no,
|
||||
'transfer_amount' => $this->transfer_amount,
|
||||
'transfer_remark' => $this->transfer_remark,
|
||||
'openid' => $this->openid,
|
||||
'user_name' => $this->user_name,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,37 +10,44 @@ class WxV3AppPayment extends SmallProgram
|
||||
{
|
||||
|
||||
|
||||
use WxV3PaymentTait;
|
||||
use WxV3PaymentTait;
|
||||
|
||||
|
||||
/**
|
||||
* @param $orderNo
|
||||
* @param int $total
|
||||
* @param string|null $openId
|
||||
* @param string $payer_client_ip
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function payment($orderNo, int $total, string $openId = NULL, string $payer_client_ip = '127.0.0.1'): array
|
||||
{
|
||||
$body = $this->getInitCore($orderNo, $total);
|
||||
/**
|
||||
* @param $orderNo
|
||||
* @param int $total
|
||||
* @param string|null $openId
|
||||
* @param string $payer_client_ip
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function payment($orderNo, int $total, string $openId = NULL, string $payer_client_ip = '127.0.0.1'): array
|
||||
{
|
||||
$body = $this->getInitCore($orderNo, $total);
|
||||
|
||||
$body['scene_info'] = ['payer_client_ip' => $payer_client_ip];
|
||||
$body['scene_info'] = ['payer_client_ip' => $payer_client_ip];
|
||||
|
||||
$sign = $this->signature('POST', '/v3/pay/transactions/components', $json = json_encode($body, JSON_UNESCAPED_UNICODE));
|
||||
$sign = $this->signature('POST', '/v3/pay/transactions/components', $json = json_encode($body, JSON_UNESCAPED_UNICODE));
|
||||
|
||||
$client = new Client('api.mch.weixin.qq.com', 443, TRUE);
|
||||
$client->withAddedHeader('Authorization', $sign)->withContentType('application/json')
|
||||
->withAgent('application/json')->withBody($json)
|
||||
->post('/v3/pay/transactions/components');
|
||||
$client->close();
|
||||
$client = new Client('api.mch.weixin.qq.com', 443, TRUE);
|
||||
$client->withAddedHeader('Authorization', $sign)->withContentType('application/json')
|
||||
->withAgent('application/json')->withBody($json)->withAddedHeader("Accept", "*/*");
|
||||
|
||||
$json = json_decode($client->getBody(), TRUE);
|
||||
if (!isset($json['prepay_id'])) {
|
||||
throw new Exception('微信支付调用失败');
|
||||
}
|
||||
return $this->createResponse($json, $body);
|
||||
}
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
|
||||
$client->post('/v3/pay/transactions/components');
|
||||
$client->close();
|
||||
|
||||
$json = json_decode($client->getBody(), TRUE);
|
||||
if (!isset($json['prepay_id'])) {
|
||||
throw new Exception('微信支付调用失败');
|
||||
}
|
||||
return $this->createResponse($json, $body);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace wchat\wx\V3;
|
||||
|
||||
use Exception;
|
||||
use Kiri\Client;
|
||||
use Kiri\Message\Stream;
|
||||
use JetBrains\PhpStorm\ArrayShape;
|
||||
use wchat\wx\SmallProgram;
|
||||
|
||||
@@ -32,8 +31,15 @@ class WxV3NativePayment extends SmallProgram
|
||||
|
||||
$client = new Client('api.mch.weixin.qq.com', 443, TRUE);
|
||||
$client->withAddedHeader('Authorization', $sign)->withContentType('application/json')
|
||||
->withAgent('application/json')->withBody(new Stream($json))
|
||||
->post('/v3/pay/transactions/native');
|
||||
->withAgent('application/json')->withBody($json)->withAddedHeader("Accept", "*/*");
|
||||
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
|
||||
$client->post('/v3/pay/transactions/native');
|
||||
$client->close();
|
||||
|
||||
$json = json_decode($client->getBody(), TRUE);
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace wchat\wx\V3;
|
||||
|
||||
use Exception;
|
||||
use Kiri\Client;
|
||||
use Kiri\Message\Stream;
|
||||
use wchat\wx\SmallProgram;
|
||||
|
||||
class WxV3Payment extends SmallProgram
|
||||
@@ -32,10 +31,16 @@ class WxV3Payment extends SmallProgram
|
||||
|
||||
$client = new Client('api.mch.weixin.qq.com', 443, TRUE);
|
||||
$client->withAddedHeader('Authorization', $sign)
|
||||
->withContentType('application/json')
|
||||
->withAddedHeader('User-Agent', 'application/json')
|
||||
->withBody(new Stream($json))
|
||||
->post('/v3/pay/transactions/jsapi');
|
||||
->withContentType('application/json')->withAddedHeader('User-Agent', 'application/json')
|
||||
->withBody($json)->withAddedHeader("Accept", "*/*");
|
||||
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
|
||||
$client->post('/v3/pay/transactions/jsapi');
|
||||
$client->close();
|
||||
|
||||
$json = json_decode($client->getBody(), TRUE);
|
||||
|
||||
@@ -7,108 +7,111 @@ use wchat\common\Help;
|
||||
use function Sodium\crypto_aead_aes256gcm_decrypt;
|
||||
use function Sodium\crypto_aead_aes256gcm_is_available;
|
||||
|
||||
const KEY_LENGTH_BYTE = 32;
|
||||
const KEY_LENGTH_BYTE = 32;
|
||||
const AUTH_TAG_LENGTH_BYTE = 16;
|
||||
|
||||
trait WxV3PaymentTait
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $orderNo
|
||||
* @param $total
|
||||
* @return array
|
||||
*/
|
||||
public function getInitCore($orderNo, $total): array
|
||||
{
|
||||
$body['appid'] = $this->getConfig()->getAppid();
|
||||
$body['mchid'] = $this->getConfig()->getMchId();
|
||||
$body['description'] = $this->getConfig()->getBody();
|
||||
$body['out_trade_no'] = $orderNo;
|
||||
$body['notify_url'] = $this->getConfig()->getNotifyUrl();
|
||||
$body['amount'] = ['total' => $total, 'currency' => 'CNY'];
|
||||
return $body;
|
||||
}
|
||||
/**
|
||||
* @param $orderNo
|
||||
* @param $total
|
||||
* @return array
|
||||
*/
|
||||
public function getInitCore($orderNo, $total): array
|
||||
{
|
||||
$body['appid'] = $this->getConfig()->getAppid();
|
||||
$body['mchid'] = $this->getConfig()->getMchId();
|
||||
$body['description'] = $this->getConfig()->getBody();
|
||||
$body['out_trade_no'] = $orderNo;
|
||||
$body['notify_url'] = $this->getConfig()->getNotifyUrl();
|
||||
$body['amount'] = ['total' => $total, 'currency' => 'CNY'];
|
||||
return $body;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $http_method
|
||||
* @param string $canonical_url
|
||||
* @param string $body
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function signature(string $http_method, string $canonical_url, string $body = ''): string
|
||||
{
|
||||
$message = $http_method . "\n" . $canonical_url . "\n" . ($time = time()) . "\n" . ($rand = md5(random_bytes(32))) . "\n" . $body . "\n";
|
||||
/**
|
||||
* @param string $http_method
|
||||
* @param string $canonical_url
|
||||
* @param string $body
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function signature(string $http_method, string $canonical_url, string $body = ''): string
|
||||
{
|
||||
$rand = md5(random_bytes(32));
|
||||
$time = time();
|
||||
|
||||
$sign = $this->openssl_signature($message);
|
||||
$message = sprintf("%s\n%s\n%d\n%s\n%s\n", $http_method, $canonical_url, $time, $rand, $body);
|
||||
|
||||
return sprintf('%s mchid="%s",nonce_str="%s",timestamp="%d",serial_no="%s",signature="%s"', $this->getConfig()->getSchema(),
|
||||
$this->getConfig()->getMchId(), $rand, $time, $this->getConfig()->getSerialNo(), $sign);
|
||||
}
|
||||
$sign = $this->openssl_signature($message);
|
||||
|
||||
return sprintf('%s mchid="%s",nonce_str="%s",timestamp="%d",serial_no="%s",signature="%s"', $this->getConfig()->getSchema(),
|
||||
$this->getConfig()->getMchId(), $rand, $time, $this->getConfig()->getSerialNo(), $sign);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $body
|
||||
* @return string
|
||||
*/
|
||||
public function openssl_signature($body): string
|
||||
{
|
||||
$pem = file_get_contents($this->getConfig()->getSslCert());
|
||||
/**
|
||||
* @param $body
|
||||
* @return string
|
||||
*/
|
||||
public function openssl_signature($body): string
|
||||
{
|
||||
$pem = file_get_contents($this->getConfig()->getMchKey());
|
||||
|
||||
$mch_private_key = openssl_get_privatekey($pem);
|
||||
$mch_private_key = openssl_get_privatekey($pem);
|
||||
|
||||
openssl_sign($body, $raw_sign, $mch_private_key, 'sha256WithRSAEncryption');
|
||||
return base64_encode($raw_sign);
|
||||
}
|
||||
openssl_sign($body, $raw_sign, $mch_private_key, 'sha256WithRSAEncryption');
|
||||
return base64_encode($raw_sign);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $json
|
||||
* @param $body
|
||||
* @return array
|
||||
*/
|
||||
private function createResponse($json, $body): array
|
||||
{
|
||||
$responseArray['appId'] = $body['appid'];
|
||||
$responseArray['timeStamp'] = (string)time();
|
||||
$responseArray['nonceStr'] = Help::random(32);
|
||||
$responseArray['package'] = "prepay_id=" . $json['prepay_id'];
|
||||
/**
|
||||
* @param $json
|
||||
* @param $body
|
||||
* @return array
|
||||
*/
|
||||
private function createResponse($json, $body): array
|
||||
{
|
||||
$responseArray['appId'] = $body['appid'];
|
||||
$responseArray['timeStamp'] = (string)time();
|
||||
$responseArray['nonceStr'] = Help::random(32);
|
||||
$responseArray['package'] = "prepay_id=" . $json['prepay_id'];
|
||||
|
||||
$responseBody = $responseArray['appId'] . PHP_EOL . $responseArray['timeStamp'] . PHP_EOL . $responseArray['nonceStr'] . PHP_EOL . $responseArray['package'] . PHP_EOL;
|
||||
$responseBody = $responseArray['appId'] . PHP_EOL . $responseArray['timeStamp'] . PHP_EOL . $responseArray['nonceStr'] . PHP_EOL . $responseArray['package'] . PHP_EOL;
|
||||
|
||||
$responseArray['signType'] = 'RSA';
|
||||
$responseArray['signBody'] = $responseBody;
|
||||
$responseArray['paySign'] = $this->openssl_signature($responseBody);
|
||||
$responseArray['prepay_id'] = $json['prepay_id'];
|
||||
$responseArray['signType'] = 'RSA';
|
||||
$responseArray['signBody'] = $responseBody;
|
||||
$responseArray['paySign'] = $this->openssl_signature($responseBody);
|
||||
$responseArray['prepay_id'] = $json['prepay_id'];
|
||||
|
||||
return $responseArray;
|
||||
}
|
||||
return $responseArray;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $associatedData
|
||||
* @param $nonceStr
|
||||
* @param $ciphertext
|
||||
* @return bool|string
|
||||
*/
|
||||
public function decryptToString($associatedData, $nonceStr, $ciphertext): bool|string
|
||||
{
|
||||
$ciphertext = \base64_decode($ciphertext);
|
||||
if (strlen($ciphertext) <= AUTH_TAG_LENGTH_BYTE) {
|
||||
return FALSE;
|
||||
}
|
||||
if (function_exists('\sodium\crypto_aead_aes256gcm_is_available') && crypto_aead_aes256gcm_is_available()) {
|
||||
return crypto_aead_aes256gcm_decrypt($ciphertext, $associatedData, $nonceStr, 'XGwwZbmMXy6sD5w0IrxfaBHLl7b7jCaR');
|
||||
}
|
||||
if (function_exists('\Sodium\crypto_aead_aes256gcm_is_available') && crypto_aead_aes256gcm_is_available()) {
|
||||
return crypto_aead_aes256gcm_decrypt($ciphertext, $associatedData, $nonceStr, 'XGwwZbmMXy6sD5w0IrxfaBHLl7b7jCaR');
|
||||
}
|
||||
if (PHP_VERSION_ID >= 70100 && in_array('aes-256-gcm', \openssl_get_cipher_methods())) {
|
||||
$ctext = substr($ciphertext, 0, -AUTH_TAG_LENGTH_BYTE);
|
||||
$authTag = substr($ciphertext, -AUTH_TAG_LENGTH_BYTE);
|
||||
return \openssl_decrypt($ctext, 'aes-256-gcm', 'XGwwZbmMXy6sD5w0IrxfaBHLl7b7jCaR', \OPENSSL_RAW_DATA, $nonceStr, $authTag, $associatedData);
|
||||
}
|
||||
throw new \RuntimeException('AEAD_AES_256_GCM需要PHP 7.1以上或者安装libsodium-php');
|
||||
}
|
||||
/**
|
||||
* @param $associatedData
|
||||
* @param $nonceStr
|
||||
* @param $ciphertext
|
||||
* @return bool|string
|
||||
*/
|
||||
public function decryptToString($associatedData, $nonceStr, $ciphertext): bool|string
|
||||
{
|
||||
$ciphertext = \base64_decode($ciphertext);
|
||||
if (strlen($ciphertext) <= AUTH_TAG_LENGTH_BYTE) {
|
||||
return FALSE;
|
||||
}
|
||||
if (function_exists('\sodium\crypto_aead_aes256gcm_is_available') && crypto_aead_aes256gcm_is_available()) {
|
||||
return crypto_aead_aes256gcm_decrypt($ciphertext, $associatedData, $nonceStr, 'XGwwZbmMXy6sD5w0IrxfaBHLl7b7jCaR');
|
||||
}
|
||||
if (function_exists('\Sodium\crypto_aead_aes256gcm_is_available') && crypto_aead_aes256gcm_is_available()) {
|
||||
return crypto_aead_aes256gcm_decrypt($ciphertext, $associatedData, $nonceStr, 'XGwwZbmMXy6sD5w0IrxfaBHLl7b7jCaR');
|
||||
}
|
||||
if (PHP_VERSION_ID >= 70100 && in_array('aes-256-gcm', \openssl_get_cipher_methods())) {
|
||||
$ctext = substr($ciphertext, 0, -AUTH_TAG_LENGTH_BYTE);
|
||||
$authTag = substr($ciphertext, -AUTH_TAG_LENGTH_BYTE);
|
||||
return \openssl_decrypt($ctext, 'aes-256-gcm', 'XGwwZbmMXy6sD5w0IrxfaBHLl7b7jCaR', \OPENSSL_RAW_DATA, $nonceStr, $authTag, $associatedData);
|
||||
}
|
||||
throw new \RuntimeException('AEAD_AES_256_GCM需要PHP 7.1以上或者安装libsodium-php');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,56 +12,62 @@ class WxV3Withdrawal extends SmallProgram
|
||||
{
|
||||
|
||||
|
||||
use WxV3PaymentTait;
|
||||
use WxV3PaymentTait;
|
||||
|
||||
|
||||
/**
|
||||
* @param $orderNo
|
||||
* @param string $batch_name
|
||||
* @param string $batch_remark
|
||||
* @param TransferDetail[] $details
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function payment($orderNo, string $batch_name, string $batch_remark, array $details): array
|
||||
{
|
||||
$body = $this->create($orderNo, $batch_name, $batch_remark, $details);
|
||||
/**
|
||||
* @param $orderNo
|
||||
* @param string $batch_name
|
||||
* @param string $batch_remark
|
||||
* @param TransferDetail[] $details
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function payment($orderNo, string $batch_name, string $batch_remark, array $details): array
|
||||
{
|
||||
$body = $this->create($orderNo, $batch_name, $batch_remark, $details);
|
||||
|
||||
$sign = $this->signature('POST', '/v3/pay/transactions/batches', $json = json_encode($body, JSON_UNESCAPED_UNICODE));
|
||||
$sign = $this->signature('POST', '/v3/pay/transactions/batches', $json = json_encode($body, JSON_UNESCAPED_UNICODE));
|
||||
|
||||
$client = new Client('api.mch.weixin.qq.com', 443, TRUE);
|
||||
$client->withAddedHeader('Authorization', $sign)
|
||||
->withContentType('application/json')
|
||||
->withAddedHeader('User-Agent', 'application/json')
|
||||
->withBody(new Stream($json))
|
||||
->post('/v3/pay/transactions/batches');
|
||||
$client->close();
|
||||
$client = new Client('api.mch.weixin.qq.com', 443, TRUE);
|
||||
$client->withAddedHeader('Authorization', $sign)
|
||||
->withContentType('application/json')->withAddedHeader('User-Agent', 'application/json')
|
||||
->withBody($json)->withAddedHeader("Accept", "*/*");
|
||||
|
||||
$json = json_decode($client->getBody(), TRUE);
|
||||
if (!isset($json['prepay_id'])) {
|
||||
throw new Exception('微信支付调用失败');
|
||||
}
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
|
||||
return $this->createResponse($json, $body);
|
||||
}
|
||||
$client->post('/v3/pay/transactions/batches');
|
||||
$client->close();
|
||||
|
||||
$json = json_decode($client->getBody(), TRUE);
|
||||
if (!isset($json['prepay_id'])) {
|
||||
throw new Exception('微信支付调用失败');
|
||||
}
|
||||
|
||||
return $this->createResponse($json, $body);
|
||||
}
|
||||
|
||||
|
||||
#[ArrayShape(['transfer_detail_list' => "array", 'total_amount' => "int", 'total_num' => "int", 'batch_remark' => "string", 'batch_name' => "string", 'out_batch_no' => ""])]
|
||||
private function create($orderNo, string $batch_name, string $batch_remark, array $details): array
|
||||
{
|
||||
$total = 0;
|
||||
$body = ['transfer_detail_list' => []];
|
||||
$body['out_batch_no'] = $orderNo;
|
||||
$body['batch_name'] = $batch_name;
|
||||
$body['batch_remark'] = $batch_remark;
|
||||
$body['total_num'] = count($details);
|
||||
foreach ($details as $detail) {
|
||||
$total += $detail->transfer_amount;
|
||||
$body['transfer_detail_list'][] = $detail->toArray();
|
||||
}
|
||||
$body['total_amount'] = $total;
|
||||
return $body;
|
||||
}
|
||||
#[ArrayShape(['transfer_detail_list' => "array", 'total_amount' => "int", 'total_num' => "int", 'batch_remark' => "string", 'batch_name' => "string", 'out_batch_no' => ""])]
|
||||
private function create($orderNo, string $batch_name, string $batch_remark, array $details): array
|
||||
{
|
||||
$total = 0;
|
||||
$body = ['transfer_detail_list' => []];
|
||||
$body['out_batch_no'] = $orderNo;
|
||||
$body['batch_name'] = $batch_name;
|
||||
$body['batch_remark'] = $batch_remark;
|
||||
$body['total_num'] = count($details);
|
||||
foreach ($details as $detail) {
|
||||
$total += $detail->transfer_amount;
|
||||
$body['transfer_detail_list'][] = $detail->toArray();
|
||||
}
|
||||
$body['total_amount'] = $total;
|
||||
return $body;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user