add clear

This commit is contained in:
2022-09-09 16:42:55 +08:00
parent ad76b45b45
commit 7273fe1ce5
63 changed files with 2625 additions and 5287 deletions
+176 -194
View File
@@ -3,399 +3,388 @@
namespace wchat\qq;
use Kiri\Client;
use wchat\common\Help;
use wchat\common\Result;
use qq\result\RedHatResult;
class Redhat extends SmallProgram
{
private $charset = 'UTF8';
private $nonce_str = '';
private $sign = '';
private $mch_billno = '';
private $mch_id = '';
private $mch_name = '';
private $qqappid = '';
private $re_openid = '';
private $total_amount = '';
private $total_num = '';
private $wishing = '';
private $act_name = '';
private $icon_id = '';
private $banner_id = '';
private $notify_url = '';
private $not_send_msg = '';
private $min_value = '';
private $max_value = '';
private $key = '';
private $signType = '';
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 = '';
private string $wishing = '';
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 $sendUrl = 'https://api.qpay.qq.com/cgi-bin/hongbao/qpay_hb_mch_send.cgi';
private $searchUrl = 'https://qpay.qq.com/cgi-bin/mch_query/qpay_hb_mch_list_query.cgi';
private string $sendUrl = '/cgi-bin/hongbao/qpay_hb_mch_send.cgi';
private string $searchUrl = '/cgi-bin/mch_query/qpay_hb_mch_list_query.cgi';
/**
* @return string
*/
public function getKey()
{
return $this->key;
}
/**
* @param $key
* @return Redhat
*/
public function setKey($key): Redhat
{
$this->key = $key;
return $this;
}
/**
* @return string
*/
public function getSignType()
{
return $this->signType;
}
/**
* @param $signType
* @return Redhat
*/
public function setSignType($signType): Redhat
{
$this->signType = $signType;
return $this;
}
/**
* @return string
*/
public function getCharset()
public function getCharset(): string
{
return $this->charset;
}
/**
* @param $charset
* @return Redhat
* @param string $charset
*/
public function setCharset($charset): Redhat
public function setCharset(string $charset): void
{
$this->charset = $charset;
return $this;
}
/**
* @return string
*/
public function getNonceStr()
public function getNonceStr(): string
{
return $this->nonce_str;
}
/**
* @param $nonce_str
* @return Redhat
* @param string $nonce_str
*/
public function setNonceStr($nonce_str): Redhat
public function setNonceStr(string $nonce_str): void
{
$this->nonce_str = $nonce_str;
return $this;
}
/**
* @return string
*/
public function getSign()
public function getSign(): string
{
return $this->sign;
}
/**
* @param $sign
* @return Redhat
* @param string $sign
*/
public function setSign($sign): Redhat
public function setSign(string $sign): void
{
$this->sign = $sign;
return $this;
}
/**
* @return string
*/
public function getMchBillno()
public function getMchBillno(): string
{
if (empty($this->mch_billno)) {
return '1559179381' . date('Ymd') . mt_rand(11, 99) . date('His') . mt_rand(11, 99);
}
return $this->mch_billno;
}
/**
* @param $mch_billno
* @return Redhat
* @param string $mch_billno
*/
public function setMchBillno($mch_billno): Redhat
public function setMchBillno(string $mch_billno): void
{
$this->mch_billno = $mch_billno;
return $this;
}
/**
* @return string
*/
public function getMchId()
public function getMchId(): string
{
return $this->mch_id;
}
/**
* @param $mch_id
* @return Redhat
* @param string $mch_id
*/
public function setMchId($mch_id): Redhat
public function setMchId(string $mch_id): void
{
$this->mch_id = $mch_id;
return $this;
}
/**
* @return string
*/
public function getMchName()
public function getMchName(): string
{
return $this->mch_name;
}
/**
* @param $mch_name
* @return Redhat
* @param string $mch_name
*/
public function setMchName($mch_name): Redhat
public function setMchName(string $mch_name): void
{
$this->mch_name = $mch_name;
return $this;
}
/**
* @return string
*/
public function getQqappid()
public function getQqappid(): string
{
return $this->qqappid;
}
/**
* @param $qqappid
* @return Redhat
* @param string $qqappid
*/
public function setQqappid($qqappid): Redhat
public function setQqappid(string $qqappid): void
{
$this->qqappid = $qqappid;
return $this;
}
/**
* @return string
*/
public function getReOpenid()
public function getReOpenid(): string
{
return $this->re_openid;
}
/**
* @param $re_openid
* @return Redhat
* @param string $re_openid
*/
public function setReOpenid($re_openid): Redhat
public function setReOpenid(string $re_openid): void
{
$this->re_openid = $re_openid;
return $this;
}
/**
* @return string
*/
public function getTotalAmount()
public function getTotalAmount(): string
{
return $this->total_amount;
}
/**
* @param $total_amount
* @return Redhat
* @param string $total_amount
*/
public function setTotalAmount($total_amount): Redhat
public function setTotalAmount(string $total_amount): void
{
$this->total_amount = $total_amount;
return $this;
}
/**
* @return string
*/
public function getTotalNum()
public function getTotalNum(): string
{
return $this->total_num;
}
/**
* @param $total_num
* @return Redhat
* @param string $total_num
*/
public function setTotalNum($total_num): Redhat
public function setTotalNum(string $total_num): void
{
$this->total_num = $total_num;
return $this;
}
/**
* @return string
*/
public function getWishing()
public function getWishing(): string
{
return $this->wishing;
}
/**
* @param $wishing
* @return Redhat
* @param string $wishing
*/
public function setWishing($wishing): Redhat
public function setWishing(string $wishing): void
{
$this->wishing = $wishing;
return $this;
}
/**
* @return string
*/
public function getActName()
public function getActName(): string
{
return $this->act_name;
}
/**
* @param $act_name
* @return Redhat
* @param string $act_name
*/
public function setActName($act_name): Redhat
public function setActName(string $act_name): void
{
$this->act_name = $act_name;
return $this;
}
/**
* @return string
*/
public function getIconId()
public function getIconId(): string
{
return $this->icon_id;
}
/**
* @param $icon_id
* @return Redhat
* @param string $icon_id
*/
public function setIconId($icon_id): Redhat
public function setIconId(string $icon_id): void
{
$this->icon_id = $icon_id;
return $this;
}
/**
* @return string
*/
public function getBannerId()
public function getBannerId(): string
{
return $this->banner_id;
}
/**
* @param $banner_id
* @return Redhat
* @param string $banner_id
*/
public function setBannerId($banner_id): Redhat
public function setBannerId(string $banner_id): void
{
$this->banner_id = $banner_id;
return $this;
}
/**
* @return string
*/
public function getNotifyUrl()
public function getNotifyUrl(): string
{
return $this->notify_url;
}
/**
* @param $notify_url
* @return Redhat
* @param string $notify_url
*/
public function setNotifyUrl($notify_url): Redhat
public function setNotifyUrl(string $notify_url): void
{
$this->notify_url = $notify_url;
return $this;
}
/**
* @return string
*/
public function getNotSendMsg()
public function getNotSendMsg(): string
{
return $this->not_send_msg;
}
/**
* @param $not_send_msg
* @return Redhat
* @param string $not_send_msg
*/
public function setNotSendMsg($not_send_msg): Redhat
public function setNotSendMsg(string $not_send_msg): void
{
$this->not_send_msg = $not_send_msg;
return $this;
}
/**
* @return string
*/
public function getMinValue()
public function getMinValue(): string
{
return $this->min_value;
}
/**
* @param $min_value
* @return Redhat
* @param string $min_value
*/
public function setMinValue($min_value): Redhat
public function setMinValue(string $min_value): void
{
$this->min_value = $min_value;
return $this;
}
/**
* @return string
*/
public function getMaxValue()
public function getMaxValue(): string
{
return $this->max_value;
}
/**
* @param $max_value
* @return Redhat
* @param string $max_value
*/
public function setMaxValue($max_value): Redhat
public function setMaxValue(string $max_value): void
{
$this->max_value = $max_value;
return $this;
}
/**
* @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;
}
@@ -403,8 +392,9 @@ class Redhat extends SmallProgram
* @return mixed
* 构建请求参数
*/
private function generate()
private function generate(): array
{
$requestParam = [];
$requestParam['charset'] = $this->getCharset();
$requestParam['nonce_str'] = $this->getNonceStr();
$requestParam['mch_billno'] = $this->getMchBillno();
@@ -431,48 +421,41 @@ class Redhat extends SmallProgram
* @param $requestParam
* @return string
*/
private function builderSign($requestParam)
private function builderSign($requestParam): string
{
return Help::sign($requestParam, $this->getKey(), $this->getSignType());
}
/**
* @return string
* @throws
* 发红包
* @return Result
*/
public function redEnvelopes()
public function redEnvelopes(): Result
{
$callback = function ($response) {
$json = json_decode($response, true);
if (isset($json['return_code']) && $json['return_code'] != 'SUCCESS') {
$message = $json['return_msg'] ?? $json['retmsg'];
$param = ['code' => 500, 'message' => $message];
} else if ($json['retcode'] != 0) {
$param = ['code' => $json['retcode'], 'message' => $json['retmsg']];
} else {
$param = ['code' => 0, 'message' => $json['retmsg'], 'data' => ['listid' => $json['listid']]];
}
return new Result($param);
};
$this->request->setCallback($callback);
$response = $this->request->post($this->sendUrl, $this->generate());
if (!$response->isResultsOK()) {
throw new \Exception($response->getMessage());
$client = new Client('qpay.qq.com', 443, true);
$client->withHeader(['Content-Type' => 'application/json']);
$client->post($this->sendUrl, $this->generate());
$client->close();
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
return new Result(code: 505, message: 'network error.');
}
$json = json_decode($client->getBody(), true);
if (isset($json['return_code']) && $json['return_code'] != 'SUCCESS') {
return new Result(code: 500, message: $json['return_msg'] ?? $json['retmsg']);
}
if ($json['retcode'] != 0) {
return new Result(code: $json['retcode'], message: $json['retmsg']);
} else {
return new Result(code: 0, data: $json);
}
return $response->getData('listid');
}
/**
* @param $listid
* @param null $orderNo
* @return RedHatResult
* @throws \Exception
*
* 查询红包状态
* @param $orderNo
* @return Result
*/
public function searchByOrderNo($listid, $orderNo = null)
public function searchByOrderNo($listid, $orderNo = null): Result
{
$requestParam['nonce_str'] = $this->getNonceStr();
$requestParam['mch_id'] = $this->getMchId();
@@ -481,20 +464,19 @@ class Redhat extends SmallProgram
$requestParam['mch_billno'] = $orderNo;
}
$requestParam['sign'] = $this->builderSign($requestParam);
$this->request->setCallback(function ($response) {
$response = json_decode($response, true);
if (!isset($response['result']) || $response['result'] != 0) {
$param = ['code' => 500, 'message' => $response['res_info'] ?? '订单查询失败!', 'data' => $response];
} else {
$param = ['code' => 0, 'message' => 'system success!', 'data' => $response];
}
return new Result($param);
});
$response = $this->request->get($this->searchUrl, $requestParam);
if (!$response->isResultsOK()) {
throw new \Exception($response->getMessage());
$client = new Client('qpay.qq.com', 443, true);
$client->withHeader(['Content-Type' => 'application/json']);
$client->post($this->searchUrl, $requestParam);
$client->close();
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
return new Result(code: 505, message: 'network error.');
}
$json = json_decode($client->getBody(), true);
if (isset($json['result']) && $json['result'] != 'SUCCESS') {
return new Result(code: 500, message: $response['res_info'] ?? '订单查询失败!');
} else {
return new Result(code: 0, data: $json);
}
return new RedHatResult($response->getData());
}
}