add clear
This commit is contained in:
+17
-36
@@ -8,58 +8,39 @@
|
||||
|
||||
namespace wchat\qq;
|
||||
|
||||
use Kiri\Client;
|
||||
use wchat\common\Decode;
|
||||
use wchat\common\HttpClient;
|
||||
use wchat\common\Result;
|
||||
|
||||
class Account extends SmallProgram
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $code
|
||||
* @param string $code
|
||||
* @return Result
|
||||
*/
|
||||
public function login($code)
|
||||
public function login(string $code): Result
|
||||
{
|
||||
$param['appid'] = $this->config->getAppid();
|
||||
$param['secret'] = $this->config->getAppsecret();
|
||||
$param['js_code'] = $code;
|
||||
$param['grant_type'] = 'authorization_code';
|
||||
|
||||
if (empty($code)) {
|
||||
return new Result(['code' => 404, 'message' => '临时登录凭证不能为空.']);
|
||||
$client = new Client('api.q.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
$client->get('sns/jscode2session', $param);
|
||||
$client->close();
|
||||
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
}
|
||||
$body = json_decode($client->getBody(), true);
|
||||
if (isset($body['errcode']) && $body['errcode'] != 0) {
|
||||
return new Result(code: $body['errcode'], message: $body['errmsg']);
|
||||
} else {
|
||||
return new Result(code: 0, data: $body);
|
||||
}
|
||||
|
||||
$this->request->setHost('api.q.qq.com');
|
||||
$this->request->addHeader('Host', 'api.q.qq.com');
|
||||
$this->request->setMethod(HttpClient::GET);
|
||||
$this->request->setIsSSL(true);
|
||||
$this->request->setUseSwoole($this->config->isUsrSwoole());
|
||||
|
||||
return $this->request->get('sns/jscode2session', $param);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $encryptedData
|
||||
* @param $iv
|
||||
* @param $sessionKey
|
||||
* @param $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, $asArray = false)
|
||||
{
|
||||
$decode = new Decode();
|
||||
$decode->setAppId($this->config->getAppid());
|
||||
$decode->setIv($iv);
|
||||
$decode->setEncryptedData($encryptedData);
|
||||
$decode->setSessionKey($sessionKey);
|
||||
return $decode->decode($asArray);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace wchat\qq;
|
||||
|
||||
|
||||
class GamePrePay extends SmallProgram
|
||||
{
|
||||
|
||||
private $url = 'https://api.q.qq.com/api/json/openApiPay/GamePrePay?access_token=';
|
||||
|
||||
|
||||
}
|
||||
+29
-322
@@ -12,31 +12,31 @@ use wchat\common\Help;
|
||||
*/
|
||||
class Notify extends SmallProgram
|
||||
{
|
||||
public $appid = null;
|
||||
public $mch_id = null;
|
||||
public $nonce_str = null;
|
||||
public $sign = null;
|
||||
public $device_info = null;
|
||||
public $trade_type = null;
|
||||
public $trade_state = null;
|
||||
public $bank_type = null;
|
||||
public $fee_type = null;
|
||||
public $total_fee = null;
|
||||
public $cash_fee = null;
|
||||
public $coupon_fee = null;
|
||||
public $transaction_id = null;
|
||||
public $out_trade_no = null;
|
||||
public $attach = null;
|
||||
public $time_end = null;
|
||||
public $openid = null;
|
||||
public mixed $appid = null;
|
||||
public mixed $mch_id = null;
|
||||
public mixed $nonce_str = null;
|
||||
public mixed $sign = null;
|
||||
public mixed $device_info = null;
|
||||
public mixed $trade_type = null;
|
||||
public mixed $trade_state = null;
|
||||
public mixed $bank_type = null;
|
||||
public mixed $fee_type = null;
|
||||
public mixed $total_fee = null;
|
||||
public mixed $cash_fee = null;
|
||||
public mixed $coupon_fee = null;
|
||||
public mixed $transaction_id = null;
|
||||
public mixed $out_trade_no = null;
|
||||
public mixed $attach = null;
|
||||
public mixed $time_end = null;
|
||||
public mixed $openid = null;
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* 判断是否完成支付
|
||||
*/
|
||||
public function isSuccess()
|
||||
public function isSuccess(): bool
|
||||
{
|
||||
return $this->getTradeState() === 'SUCCESS';
|
||||
return $this->trade_state === 'SUCCESS';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,26 +44,31 @@ class Notify extends SmallProgram
|
||||
* @return $this
|
||||
* @throws Exception
|
||||
*/
|
||||
public function setPayNotifyData(array $params)
|
||||
public function setPayNotifyData(array $params): static
|
||||
{
|
||||
if (!$this->validation($params)) {
|
||||
throw new Exception('签名错误!');
|
||||
}
|
||||
foreach ($params as $key => $val) {
|
||||
if (!property_exists($this, $key)) {
|
||||
continue;
|
||||
}
|
||||
$this->$key = $val;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function __set(string $name, $value): void
|
||||
{
|
||||
if (property_exists($this, $name)) {
|
||||
$this->{$name} = $value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $params
|
||||
* @return bool
|
||||
*/
|
||||
public function validation(array $params)
|
||||
public function validation(array $params): bool
|
||||
{
|
||||
$sign = $params['sign'];
|
||||
unset($params['sign']);
|
||||
@@ -85,303 +90,5 @@ class Notify extends SmallProgram
|
||||
return $this->appid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $appid
|
||||
* @return Notify
|
||||
*/
|
||||
public function setAppid($appid)
|
||||
{
|
||||
$this->appid = $appid;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getMchId()
|
||||
{
|
||||
return $this->mch_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $mch_id
|
||||
* @return Notify
|
||||
*/
|
||||
public function setMchId($mch_id)
|
||||
{
|
||||
$this->mch_id = $mch_id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getNonceStr()
|
||||
{
|
||||
return $this->nonce_str;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $nonce_str
|
||||
* @return Notify
|
||||
*/
|
||||
public function setNonceStr($nonce_str)
|
||||
{
|
||||
$this->nonce_str = $nonce_str;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getSign()
|
||||
{
|
||||
return $this->sign;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $sign
|
||||
* @return Notify
|
||||
*/
|
||||
public function setSign($sign)
|
||||
{
|
||||
$this->sign = $sign;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getDeviceInfo()
|
||||
{
|
||||
return $this->device_info;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $device_info
|
||||
* @return Notify
|
||||
*/
|
||||
public function setDeviceInfo($device_info)
|
||||
{
|
||||
$this->device_info = $device_info;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getTradeType()
|
||||
{
|
||||
return $this->trade_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $trade_type
|
||||
* @return Notify
|
||||
*/
|
||||
public function setTradeType($trade_type)
|
||||
{
|
||||
$this->trade_type = $trade_type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getTradeState()
|
||||
{
|
||||
return $this->trade_state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $trade_state
|
||||
* @return Notify
|
||||
*/
|
||||
public function setTradeState($trade_state)
|
||||
{
|
||||
$this->trade_state = $trade_state;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getBankType()
|
||||
{
|
||||
return $this->bank_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $bank_type
|
||||
* @return Notify
|
||||
*/
|
||||
public function setBankType($bank_type)
|
||||
{
|
||||
$this->bank_type = $bank_type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getFeeType()
|
||||
{
|
||||
return $this->fee_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $fee_type
|
||||
* @return Notify
|
||||
*/
|
||||
public function setFeeType($fee_type)
|
||||
{
|
||||
$this->fee_type = $fee_type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getTotalFee()
|
||||
{
|
||||
return $this->total_fee;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $total_fee
|
||||
* @return Notify
|
||||
*/
|
||||
public function setTotalFee($total_fee)
|
||||
{
|
||||
$this->total_fee = $total_fee;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getCashFee()
|
||||
{
|
||||
return $this->cash_fee;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $cash_fee
|
||||
* @return Notify
|
||||
*/
|
||||
public function setCashFee($cash_fee)
|
||||
{
|
||||
$this->cash_fee = $cash_fee;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getCouponFee()
|
||||
{
|
||||
return $this->coupon_fee;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $coupon_fee
|
||||
* @return Notify
|
||||
*/
|
||||
public function setCouponFee($coupon_fee)
|
||||
{
|
||||
$this->coupon_fee = $coupon_fee;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getTransactionId()
|
||||
{
|
||||
return $this->transaction_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $transaction_id
|
||||
* @return Notify
|
||||
*/
|
||||
public function setTransactionId($transaction_id)
|
||||
{
|
||||
$this->transaction_id = $transaction_id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getOutTradeNo()
|
||||
{
|
||||
return $this->out_trade_no;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $out_trade_no
|
||||
* @return Notify
|
||||
*/
|
||||
public function setOutTradeNo($out_trade_no)
|
||||
{
|
||||
$this->out_trade_no = $out_trade_no;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getAttach()
|
||||
{
|
||||
return $this->attach;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $attach
|
||||
* @return Notify
|
||||
*/
|
||||
public function setAttach($attach)
|
||||
{
|
||||
$this->attach = $attach;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getTimeEnd()
|
||||
{
|
||||
return $this->time_end;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $time_end
|
||||
* @return Notify
|
||||
*/
|
||||
public function setTimeEnd($time_end)
|
||||
{
|
||||
$this->time_end = $time_end;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getOpenid()
|
||||
{
|
||||
return $this->openid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $openid
|
||||
* @return Notify
|
||||
*/
|
||||
public function setOpenid($openid)
|
||||
{
|
||||
$this->openid = $openid;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace wchat\wx;
|
||||
|
||||
use Kiri\Di\Container;
|
||||
use wchat\common\Config;
|
||||
|
||||
class QqFactory
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param $class
|
||||
* @param Config $config
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get($class, Config $config): mixed
|
||||
{
|
||||
$container = Container::getInstance();
|
||||
$object = $container->get($class);
|
||||
$object->setConfig($config);
|
||||
return $object;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+41
-41
@@ -9,6 +9,7 @@
|
||||
namespace wchat\qq;
|
||||
|
||||
use Exception;
|
||||
use Kiri\Client;
|
||||
use wchat\common\HttpClient;
|
||||
use wchat\common\Result;
|
||||
use wchat\common\Help;
|
||||
@@ -35,47 +36,60 @@ class Recharge extends SmallProgram
|
||||
|
||||
/**
|
||||
* @param int $money
|
||||
* @param $orderNo
|
||||
* @param $openId
|
||||
* @return array|mixed|Result
|
||||
* @param string $orderNo
|
||||
* @param string $openId
|
||||
* @return Result
|
||||
* @throws
|
||||
*/
|
||||
public function recharge(int $money, $orderNo, $openId = '')
|
||||
public function recharge(int $money, string $orderNo, string $openId = ''): Result
|
||||
{
|
||||
if ($money < 0) {
|
||||
return new Result(['code' => 500, 'message' => '充值金额不能小于0.']);
|
||||
return new Result(code: 500, message: '充值金额不能小于0.');
|
||||
}
|
||||
$this->money = $money;
|
||||
$this->orderNo = $orderNo;
|
||||
$this->data['openid'] = $openId;
|
||||
|
||||
$this->request->setCallback(function ($result, $body) {
|
||||
$data = Help::toArray($result);
|
||||
if (isset($data['sign'])) {
|
||||
$sign = $data['sign'];
|
||||
unset($data['sign']);
|
||||
}
|
||||
if (!isset($sign)) {
|
||||
$return['code'] = -1;
|
||||
$return['message'] = '返回数据签名验证失败';
|
||||
} else {
|
||||
$return['code'] = 0;
|
||||
$return['data'] = $data;
|
||||
$return['data']['postBody'] = $body;
|
||||
if ($data['return_code'] == 'FAIL') {
|
||||
$return['code'] = -1;
|
||||
$return['message'] = $data['return_msg'];
|
||||
}
|
||||
}
|
||||
return new Result($return);
|
||||
});
|
||||
return $this->send($this->uniformer, $this->builder());
|
||||
$client = new Client('qpay.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/xml']);
|
||||
$client->withBody($this->builder());
|
||||
$client->post($this->uniformer);
|
||||
$client->close();
|
||||
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
}
|
||||
|
||||
$data = Help::toArray($client->getBody());
|
||||
if (isset($data['return_code']) && $data['return_code'] != 'SUCCESS') {
|
||||
return new Result(code: 503, message: $data['return_msg']);
|
||||
}
|
||||
if ($data['result_code'] != 'SUCCESS') {
|
||||
return new Result(code: 504, message: $data['err_code_des']);
|
||||
}
|
||||
|
||||
return new Result(code: 0, data: $this->reception($data['prepayid']));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $prepay_id
|
||||
* @return string
|
||||
*/
|
||||
public function reception(string $prepay_id): string
|
||||
{
|
||||
return Help::sign([
|
||||
'signType' => $this->config->getSignType(),
|
||||
'package' => 'prepay_id=' . $prepay_id,
|
||||
'nonceStr' => Help::random(32),
|
||||
'timestamp' => time()
|
||||
], $this->getConfig()->getKey(), $this->getConfig()->getSignType());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function builder()
|
||||
protected function builder(): string
|
||||
{
|
||||
$data = [
|
||||
'appid' => $this->config->getAppid(),
|
||||
@@ -99,18 +113,4 @@ class Recharge extends SmallProgram
|
||||
|
||||
return Help::toXml($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $url
|
||||
* @param $data
|
||||
* @return array|mixed|Result
|
||||
* @throws Exception
|
||||
*/
|
||||
private function send($url, $data)
|
||||
{
|
||||
$this->request->setIsSSL(true);
|
||||
$this->request->setMethod(HttpClient::POST);
|
||||
$this->request->addHeader('Content-Type', 'text/xml');
|
||||
return $this->request->send($url, $data);
|
||||
}
|
||||
}
|
||||
|
||||
+176
-194
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+42
-30
@@ -4,6 +4,7 @@
|
||||
namespace wchat\qq;
|
||||
|
||||
|
||||
use Kiri\Client;
|
||||
use wchat\common\Result;
|
||||
|
||||
/**
|
||||
@@ -13,57 +14,68 @@ use wchat\common\Result;
|
||||
class SecCheck extends SmallProgram
|
||||
{
|
||||
|
||||
private $_url = 'https://api.q.qq.com/api/json/security/ImgSecCheck?access_token=';
|
||||
private string $_url = '/api/json/security/ImgSecCheck?access_token=';
|
||||
|
||||
private $_msgUrl = '/api/json/security/MsgSecCheck?access_token=';
|
||||
private string $_msgUrl = '/api/json/security/MsgSecCheck?access_token=';
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
* @return array|Result|mixed
|
||||
* @param string $path
|
||||
* @return Result
|
||||
*/
|
||||
public function image($path = '')
|
||||
public function image(string $path = ''): Result
|
||||
{
|
||||
if (!file_exists($path)) {
|
||||
return $this->sendError('文件不存在', 404);
|
||||
}
|
||||
$this->request->setUseSwoole(false);
|
||||
$this->request->setHeader('Content-Type', 'multipart/form-data');
|
||||
$this->request->addHeader('Host', 'api.q.qq.com');
|
||||
$this->request->setErrorField('errCode');
|
||||
$this->request->setErrorMsgField('errMsg');
|
||||
$this->request->setAgent('');
|
||||
|
||||
$real_path = new \CURLFile($path);
|
||||
return $this->request->upload($this->_url . $this->config->getAccessToken(), [
|
||||
'appid' => $this->config->getAppid(), 'media' => new \CURLFile($path)
|
||||
, 'form-data[filename]' => $path, 'form-data[content-type]' => $real_path->getMimeType()
|
||||
]);
|
||||
$data = [
|
||||
'appid' => $this->config->getAppid(),
|
||||
'media' => $real_path,
|
||||
'form-data[filename]' => $path,
|
||||
'form-data[content-type]' => $real_path->getMimeType()
|
||||
];
|
||||
$client = new Client('api.q.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'multipart/form-data']);
|
||||
$client->upload($path, $data);
|
||||
$client->close();
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
}
|
||||
$body = json_decode($client->getBody(), true);
|
||||
if (isset($body['errCode']) && $body['errCode'] != 0) {
|
||||
return new Result(code: $body['errCode'], message: $body['errMsg']);
|
||||
} else {
|
||||
return new Result(code: 0, data: $body);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $content
|
||||
* @return array|Result|mixed
|
||||
* @param string $content
|
||||
* @return Result
|
||||
*/
|
||||
public function text($content)
|
||||
public function text(string $content): Result
|
||||
{
|
||||
if (empty($content)) {
|
||||
return $this->sendError('文件不存在', 404);
|
||||
}
|
||||
$this->request->setUseSwoole(true);
|
||||
$this->request->addHeader('Content-Type', 'application/json');
|
||||
$this->request->setErrorField('errCode');
|
||||
$this->request->setErrorMsgField('errMsg');
|
||||
$this->request->setData([
|
||||
'appid' => $this->config->getAppid(),
|
||||
'content' => $content
|
||||
]);
|
||||
$this->request->setHost('api.q.qq.com');
|
||||
$this->request->setIsSSL(true);
|
||||
$url = '/' . ltrim($this->_url, '/') . $this->config->getAccessToken();
|
||||
|
||||
$url = '/' . ltrim($this->_msgUrl, '/') . $this->config->getAccessToken();
|
||||
return $this->request->post($url);
|
||||
$client = new Client('api.q.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
$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.');
|
||||
}
|
||||
$body = json_decode($client->getBody(), true);
|
||||
if (isset($body['errCode']) && $body['errCode'] != 0) {
|
||||
return new Result(code: $body['errCode'], message: $body['errMsg']);
|
||||
} else {
|
||||
return new Result(code: 0, data: $body);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,37 +4,9 @@
|
||||
namespace wchat\qq;
|
||||
|
||||
|
||||
use wchat\common\Miniprogarampage;
|
||||
use wchat\common\Multiprogramming;
|
||||
|
||||
class SmallProgram extends Miniprogarampage
|
||||
class SmallProgram extends Multiprogramming
|
||||
{
|
||||
|
||||
protected static $instance;
|
||||
|
||||
private $url = 'https://api.q.qq.com/api/getToken';
|
||||
|
||||
|
||||
/**
|
||||
* @param $get_token
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function generateAccess_token($get_token = false)
|
||||
{
|
||||
if (!empty($this->config->getToken())) {
|
||||
return $this->config->getToken();
|
||||
}
|
||||
$query = [
|
||||
'grant_type' => 'client_credential',
|
||||
'appid' => $this->config->getAppid(),
|
||||
'secret' => $this->config->getAppsecret()
|
||||
];
|
||||
$param = $this->request->get($this->url, $query);
|
||||
if (!$param->isResultsOK()) {
|
||||
return null;
|
||||
}
|
||||
if ($get_token) {
|
||||
return $param->getData('access_token');
|
||||
}
|
||||
return $param->getData();
|
||||
}
|
||||
}
|
||||
|
||||
+10
-3
@@ -13,14 +13,21 @@ use wchat\common\Result;
|
||||
class Subject extends \wchat\base\Subject
|
||||
{
|
||||
|
||||
private $sendUrl = 'https://api.q.qq.com/api/json/subscribe/SendSubscriptionMessage';
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUrl(): string
|
||||
{
|
||||
return '/api/json/subscribe/SendSubscriptionMessage';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUrl()
|
||||
public function getHost(): string
|
||||
{
|
||||
return $this->sendUrl;
|
||||
return 'api.q.qq.com';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: whwyy
|
||||
* Date: 2018/4/8 0008
|
||||
* Time: 9:49
|
||||
*/
|
||||
|
||||
namespace wchat\qq;
|
||||
|
||||
|
||||
use wchat\common\Result;
|
||||
|
||||
/**
|
||||
* Class Template
|
||||
* @package wchat\qq
|
||||
*/
|
||||
class Template extends \wchat\base\Template
|
||||
{
|
||||
|
||||
private $sendUrl = 'https://api.q.qq.com/api/json/template/send';
|
||||
|
||||
public function getUrl()
|
||||
{
|
||||
return $this->sendUrl;
|
||||
}
|
||||
|
||||
}
|
||||
+27
-4
@@ -4,12 +4,35 @@
|
||||
namespace wchat\qq;
|
||||
|
||||
|
||||
use Kiri\Client;
|
||||
use wchat\common\Result;
|
||||
|
||||
use wchat\base\Access_Token;
|
||||
|
||||
class Token extends SmallProgram implements Access_Token
|
||||
class Token extends SmallProgram
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @return Result
|
||||
*/
|
||||
public function token(): Result
|
||||
{
|
||||
$query = [
|
||||
'grant_type' => 'client_credential',
|
||||
'appid' => $this->config->getAppid(),
|
||||
'secret' => $this->config->getAppsecret()
|
||||
];
|
||||
$client = new Client('api.q.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
$client->get('/api/getToken', $query);
|
||||
$client->close();
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: 'network error.');
|
||||
}
|
||||
$body = json_decode($client->getBody(), true);
|
||||
if (isset($body['errcode']) && $body['errcode'] != 0) {
|
||||
return new Result(code: $body['errcode'], message: $body['errmsg']);
|
||||
} else {
|
||||
return new Result(code: 0, data: $body);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+42
-50
@@ -5,6 +5,7 @@ namespace wchat\qq\pay;
|
||||
|
||||
|
||||
use Exception;
|
||||
use Kiri\Client;
|
||||
use wchat\common\Help;
|
||||
use wchat\common\HttpClient;
|
||||
use wchat\common\Result;
|
||||
@@ -17,23 +18,23 @@ use wchat\wx\SmallProgram;
|
||||
class Cash_Bonus extends SmallProgram
|
||||
{
|
||||
|
||||
public $_cash = '/cgi-bin/hongbao/qpay_hb_mch_send.cgi';
|
||||
public string $_cash = '/cgi-bin/hongbao/qpay_hb_mch_send.cgi';
|
||||
|
||||
private array $_errors = [
|
||||
'66228701' => '红包个数超出限制',
|
||||
'66228705' => '总金额超出限制',
|
||||
'66228706' => '总金额不足以按最小金额领取每个红包',
|
||||
'66228707' => '商户签名校验失败',
|
||||
'66228708' => '重入??',
|
||||
'66228709' => 'openid转换uin失败',
|
||||
'66228711' => '商户订单中的商户号有误',
|
||||
'66228712' => '商户订单中的日期超过范围',
|
||||
'66228713' => '余额不足',
|
||||
'66228715' => '用户未关注公众号,发送AIO消息失败',
|
||||
'66229716' => '用户禁用公众号,发AIO消息失败'
|
||||
];
|
||||
private array $_errors = [
|
||||
'66228701' => '红包个数超出限制',
|
||||
'66228705' => '总金额超出限制',
|
||||
'66228706' => '总金额不足以按最小金额领取每个红包',
|
||||
'66228707' => '商户签名校验失败',
|
||||
'66228708' => '重入??',
|
||||
'66228709' => 'openid转换uin失败',
|
||||
'66228711' => '商户订单中的商户号有误',
|
||||
'66228712' => '商户订单中的日期超过范围',
|
||||
'66228713' => '余额不足',
|
||||
'66228715' => '用户未关注公众号,发送AIO消息失败',
|
||||
'66229716' => '用户禁用公众号,发AIO消息失败'
|
||||
];
|
||||
|
||||
private array $_requestParams = [];
|
||||
private array $_requestParams = [];
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
@@ -83,39 +84,30 @@ class Cash_Bonus extends SmallProgram
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function mch_send($mch_billno, $openId, $price)
|
||||
public function mch_send($mch_billno, $openId, $price): Result
|
||||
{
|
||||
$client = HttpClient::NewRequest();
|
||||
$client->setIsSSL(true);
|
||||
$client->setSslCertFile($this->getConfig()->getSslCert());
|
||||
$client->setSslKeyFile($this->getConfig()->getSslKey());
|
||||
$client->setCa($this->getConfig()->getSslCa());
|
||||
$client->setUseSwoole($this->getConfig()->isUsrSwoole());
|
||||
$client->setHost('api.qpay.qq.com');
|
||||
$client->setCallback(function ($response, $requestParam) {
|
||||
$json = json_decode($response, true);
|
||||
if (isset($json['return_code']) && $json['return_code'] != 'SUCCESS') {
|
||||
$array['code'] = 500;
|
||||
$array['message'] = $json['return_msg'] ?? $json['retmsg'];
|
||||
} else if ($json['retcode'] != 0) {
|
||||
if (empty($json['retmsg']) && isset($this->_errors[$json['retcode']])) {
|
||||
$json['retmsg'] = $this->_errors[$json['retcode']];
|
||||
}
|
||||
$array['code'] = $json['retcode'];
|
||||
$array['message'] = $json['retmsg'];
|
||||
} else {
|
||||
$array['code'] = 0;
|
||||
$array['message'] = $json['retmsg'];
|
||||
$array['data'] = ['listid' => $json['listid']];
|
||||
}
|
||||
$array['data']['request'] = $requestParam;
|
||||
return new Result($array);
|
||||
});
|
||||
$response = $client->post($this->_cash, $this->orderConfig($mch_billno, $openId, $price));
|
||||
if (!$response->isResultsOK()) {
|
||||
throw new Exception($response->getMessage());
|
||||
$client = new Client('api.qpay.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
$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));
|
||||
$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']);
|
||||
} else if ($json['retcode'] != 0) {
|
||||
if (empty($json['retmsg']) && isset($this->_errors[$json['retcode']])) {
|
||||
$json['retmsg'] = $this->_errors[$json['retcode']];
|
||||
}
|
||||
return new Result(code: $json['retcode'], message: $json['retmsg']);
|
||||
} else {
|
||||
return new Result(code: 0, data: $json);
|
||||
}
|
||||
return $response->getData('listid');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,7 +116,7 @@ class Cash_Bonus extends SmallProgram
|
||||
* @param $price
|
||||
* @return array
|
||||
*/
|
||||
private function orderConfig($mch_billno, $openId, $price)
|
||||
private function orderConfig($mch_billno, $openId, $price): array
|
||||
{
|
||||
$requestParam['charset'] = 1;
|
||||
$requestParam['nonce_str'] = Help::random(32);
|
||||
@@ -138,7 +130,7 @@ class Cash_Bonus extends SmallProgram
|
||||
$requestParam['total_num'] = 1;
|
||||
$requestParam['notify_url'] = $this->getConfig()->getNotifyUrl();
|
||||
|
||||
if (!empty($this->_requestParams) && is_array($this->_requestParams)) {
|
||||
if (!empty($this->_requestParams)) {
|
||||
$requestParam = array_merge($requestParam, $this->_requestParams);
|
||||
}
|
||||
|
||||
@@ -152,7 +144,7 @@ class Cash_Bonus extends SmallProgram
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function mchOrderNo()
|
||||
public function mchOrderNo(): string
|
||||
{
|
||||
return implode([
|
||||
$this->getConfig()->getMchId(),
|
||||
@@ -168,7 +160,7 @@ class Cash_Bonus extends SmallProgram
|
||||
* @param array $requestParams
|
||||
* @return bool
|
||||
*/
|
||||
public function validator(array $requestParams)
|
||||
public function validator(array $requestParams): bool
|
||||
{
|
||||
$notifySign = $requestParams['sign'];
|
||||
unset($requestParams['sign']);
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace wchat\qq\pay;
|
||||
|
||||
|
||||
use Exception;
|
||||
use Kiri\Client;
|
||||
use wchat\common\Help;
|
||||
use wchat\common\HttpClient;
|
||||
use wchat\common\Result;
|
||||
@@ -16,7 +17,7 @@ use wchat\qq\SmallProgram;
|
||||
*/
|
||||
class Enterprise_payment extends SmallProgram
|
||||
{
|
||||
public $_cash = '/cgi-bin/epay/qpay_epay_b2c.cgi';
|
||||
public string $_cash = '/cgi-bin/epay/qpay_epay_b2c.cgi';
|
||||
|
||||
private $_errors = [
|
||||
'SYSTEMERROR' => '系统错误',
|
||||
@@ -71,34 +72,24 @@ class Enterprise_payment extends SmallProgram
|
||||
*/
|
||||
public function mch_send($mch_billno, $openId, $price)
|
||||
{
|
||||
$client = HttpClient::NewRequest();
|
||||
$client->setIsSSL(true);
|
||||
$client->setSslCertFile($this->getConfig()->getSslCert());
|
||||
$client->setSslKeyFile($this->getConfig()->getSslKey());
|
||||
$client->setCa($this->getConfig()->getSslCa());
|
||||
$client->setUseSwoole($this->getConfig()->isUsrSwoole());
|
||||
$client->setHost('api.qpay.qq.com');
|
||||
$client->setCallback(function ($response, $requestParam) {
|
||||
$json = json_decode($response, true);
|
||||
if (isset($json['return_code']) && $json['return_code'] != 'SUCCESS') {
|
||||
$array['code'] = 500;
|
||||
$array['message'] = $json['return_msg'] ?? $json['retmsg'];
|
||||
} else if ($json['result_code'] != 'SUCCESS') {
|
||||
$array['code'] = 500;
|
||||
$array['message'] = $this->_errors[$json['err_code']] ?? $json['err_code_desc'];
|
||||
} else {
|
||||
$array['code'] = 0;
|
||||
$array['message'] = 'system success';
|
||||
$array['data'] = $json;
|
||||
}
|
||||
$array['data']['request'] = $requestParam;
|
||||
return new Result($array);
|
||||
});
|
||||
$response = $client->post($this->_cash, $this->orderConfig($mch_billno, $openId, $price));
|
||||
if (!$response->isResultsOK()) {
|
||||
throw new Exception($response->getMessage());
|
||||
$client = new Client('api.qpay.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
$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));
|
||||
$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, data: $json['return_msg'] ?? $json['retmsg']);
|
||||
} else if ($json['result_code'] != 'SUCCESS') {
|
||||
return new Result(code: 500, data: $this->_errors[$json['err_code']] ?? $json['err_code_desc']);
|
||||
} else {
|
||||
return new Result(code: 0, data: $json);
|
||||
}
|
||||
return $response->getData();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,7 +98,7 @@ class Enterprise_payment extends SmallProgram
|
||||
* @param $price
|
||||
* @return array
|
||||
*/
|
||||
private function orderConfig($mch_billno, $openId, $price)
|
||||
private function orderConfig($mch_billno, $openId, $price): array
|
||||
{
|
||||
$requestParam['input_charset'] = 'UTF-8';
|
||||
$requestParam['nonce_str'] = Help::random(32);
|
||||
@@ -135,7 +126,7 @@ class Enterprise_payment extends SmallProgram
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function mchOrderNo()
|
||||
public function mchOrderNo(): string
|
||||
{
|
||||
return implode([
|
||||
$this->getConfig()->getMchId(),
|
||||
@@ -151,7 +142,7 @@ class Enterprise_payment extends SmallProgram
|
||||
* @param array $requestParams
|
||||
* @return bool
|
||||
*/
|
||||
public function validator(array $requestParams)
|
||||
public function validator(array $requestParams): bool
|
||||
{
|
||||
$notifySign = $requestParams['sign'];
|
||||
unset($requestParams['sign']);
|
||||
|
||||
@@ -10,17 +10,17 @@ namespace wchat\qq\result;
|
||||
class RedHatResult
|
||||
{
|
||||
|
||||
public $result;
|
||||
public $res_info;
|
||||
public mixed $result;
|
||||
public mixed $res_info;
|
||||
|
||||
public $listid;
|
||||
public $state;
|
||||
public $total_num;
|
||||
public $recv_num;
|
||||
public $total_amount;
|
||||
public $recv_amount;
|
||||
public $recv_details;
|
||||
public $uin;
|
||||
public mixed $listid;
|
||||
public mixed $state;
|
||||
public mixed $total_num;
|
||||
public mixed $recv_num;
|
||||
public mixed $total_amount;
|
||||
public mixed $recv_amount;
|
||||
public mixed $recv_details;
|
||||
public mixed $uin;
|
||||
|
||||
|
||||
const RED_HAT_STATUS_PAID = 1;
|
||||
@@ -40,9 +40,9 @@ class RedHatResult
|
||||
|
||||
/**
|
||||
* @param $array
|
||||
* @return $this
|
||||
* @return void
|
||||
*/
|
||||
private function init($array)
|
||||
private function init($array): void
|
||||
{
|
||||
foreach ($array as $key => $value) {
|
||||
if (!property_exists($this, $key)) {
|
||||
@@ -50,7 +50,6 @@ class RedHatResult
|
||||
}
|
||||
$this->{$key} = $value;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +57,7 @@ class RedHatResult
|
||||
* @param $field
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($field)
|
||||
public function get($field): mixed
|
||||
{
|
||||
return $this->$field;
|
||||
}
|
||||
@@ -68,7 +67,7 @@ class RedHatResult
|
||||
* @return bool
|
||||
* 是否已完成支付
|
||||
*/
|
||||
public function isPaid()
|
||||
public function isPaid(): bool
|
||||
{
|
||||
return $this->state == self::RED_HAT_STATUS_PAID;
|
||||
}
|
||||
@@ -77,7 +76,7 @@ class RedHatResult
|
||||
* @return bool
|
||||
* 是否已抢完
|
||||
*/
|
||||
public function isSnatched()
|
||||
public function isSnatched(): bool
|
||||
{
|
||||
return $this->state == self::RED_HAT_STATUS_SNATCHED;
|
||||
}
|
||||
@@ -86,17 +85,16 @@ class RedHatResult
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isExpired()
|
||||
public function isExpired(): bool
|
||||
{
|
||||
return $this->state == self::RED_HAT_STATUS_EXPIRED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isRefunded()
|
||||
public function isRefunded(): bool
|
||||
{
|
||||
return $this->state == self::RED_HAT_STATUS_REFUNDED;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user