add clear
This commit is contained in:
+3
-81
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
namespace wchat\qq;
|
namespace wchat\qq;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use wchat\common\HttpClient;
|
use wchat\common\HttpClient;
|
||||||
use wchat\common\Result;
|
use wchat\common\Result;
|
||||||
use wchat\common\Help;
|
use wchat\common\Help;
|
||||||
@@ -20,7 +21,6 @@ class Recharge extends SmallProgram
|
|||||||
|
|
||||||
private $data = [];
|
private $data = [];
|
||||||
|
|
||||||
private $transfers = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers';
|
|
||||||
private $unifiedorder = 'https://qpay.qq.com/cgi-bin/pay/qpay_unified_order.cgi';
|
private $unifiedorder = 'https://qpay.qq.com/cgi-bin/pay/qpay_unified_order.cgi';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,22 +39,16 @@ class Recharge extends SmallProgram
|
|||||||
$this->orderNo = $orderNo;
|
$this->orderNo = $orderNo;
|
||||||
$this->data['openid'] = $openId;
|
$this->data['openid'] = $openId;
|
||||||
|
|
||||||
$config = $this->config;
|
$this->request->setCallback(function ($result, $body) {
|
||||||
$this->request->setCallback(function ($result, $body) use ($config) {
|
|
||||||
$data = Help::toArray($result);
|
$data = Help::toArray($result);
|
||||||
if (isset($data['sign'])) {
|
if (isset($data['sign'])) {
|
||||||
$sign = $data['sign'];
|
$sign = $data['sign'];
|
||||||
unset($data['sign']);
|
unset($data['sign']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$return = [];
|
|
||||||
// $_sign = Help::sign($data, $config->getKey(), $config->getSignType());
|
|
||||||
if (!isset($sign)) {
|
if (!isset($sign)) {
|
||||||
$return['code'] = -1;
|
$return['code'] = -1;
|
||||||
$return['message'] = '返回数据签名验证失败';
|
$return['message'] = '返回数据签名验证失败';
|
||||||
// } else if ($sign != $_sign) {
|
|
||||||
// $return['code'] = 401;
|
|
||||||
// $return['message'] = '预支付系统数据签名验证失败!';
|
|
||||||
} else {
|
} else {
|
||||||
$data['postBody'] = $body;
|
$data['postBody'] = $body;
|
||||||
|
|
||||||
@@ -70,31 +64,6 @@ class Recharge extends SmallProgram
|
|||||||
return $this->send($this->unifiedorder, $this->builder());
|
return $this->send($this->unifiedorder, $this->builder());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 'appId' => $result['appid'],
|
|
||||||
* 'nonceStr' => $result['nonce_str'],
|
|
||||||
* 'package' => 'prepay_id=' . $result['prepay_id'],
|
|
||||||
* 'signType' => 'MD5',
|
|
||||||
* 'timeStamp' => (string)time(),
|
|
||||||
* @param $prepay_id
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function reception($prepay_id)
|
|
||||||
{
|
|
||||||
$array = [
|
|
||||||
'appId' => $this->config->getAppid(),
|
|
||||||
'nonceStr' => Help::random(32),
|
|
||||||
'package' => 'prepay_id=' . $prepay_id,
|
|
||||||
'signType' => 'MD5',
|
|
||||||
'timeStamp' => (string)time(),
|
|
||||||
];
|
|
||||||
$key = $this->config->getKey();
|
|
||||||
$sign_type = $this->config->getSignType();
|
|
||||||
$array['paySign'] = Help::sign($array, $key, $sign_type);
|
|
||||||
$array['appId'] = $this->config->getAppid();
|
|
||||||
return $array;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@@ -123,58 +92,11 @@ class Recharge extends SmallProgram
|
|||||||
return Help::toXml($this->data);
|
return Help::toXml($this->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSignData()
|
|
||||||
{
|
|
||||||
$data = $this->data;
|
|
||||||
$data['key'] = $this->config->getKey();
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $money
|
|
||||||
* @param $openid
|
|
||||||
* @param $order
|
|
||||||
* @param $desc
|
|
||||||
* @return Result
|
|
||||||
* @throws
|
|
||||||
*
|
|
||||||
* 提现
|
|
||||||
*/
|
|
||||||
public function cashWithdrawal($money, $openid, $order, $desc = '零钱提现')
|
|
||||||
{
|
|
||||||
$array = [
|
|
||||||
'nonce_str' => Help::random(32),
|
|
||||||
'partner_trade_no' => $order,
|
|
||||||
'mchid' => $this->config->getMchId(),
|
|
||||||
'mch_appid' => $this->config->getAppid(),
|
|
||||||
'openid' => $openid,
|
|
||||||
'check_name' => 'NO_CHECK',
|
|
||||||
'amount' => $money * 100,
|
|
||||||
'spbill_create_ip' => $this->config->getRemoteAddr(),
|
|
||||||
'desc' => $desc,
|
|
||||||
];
|
|
||||||
|
|
||||||
$key = $this->config->getKey();
|
|
||||||
$sign_type = $this->config->getSignType();
|
|
||||||
$array['sign'] = Help::sign($array, $key, $sign_type);
|
|
||||||
|
|
||||||
$this->request->setCallback(function ($data) {
|
|
||||||
$array = Help::toArray($data);
|
|
||||||
if ($array['result_code'] != 'SUCCESS') {
|
|
||||||
$data = ['code' => $array['err_code'], 'message' => $array['err_code_des']];
|
|
||||||
} else {
|
|
||||||
$data = ['code' => 0, 'message' => '支付成功'];
|
|
||||||
}
|
|
||||||
return new Result($data);
|
|
||||||
});
|
|
||||||
return $this->send($this->transfers, Help::toXml($array));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $url
|
* @param $url
|
||||||
* @param $data
|
* @param $data
|
||||||
* @return array|mixed|Result
|
* @return array|mixed|Result
|
||||||
* @throws \Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private function send($url, $data)
|
private function send($url, $data)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,185 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace wchat\qq\pay;
|
||||||
|
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use wchat\common\Help;
|
||||||
|
use wchat\common\HttpClient;
|
||||||
|
use wchat\common\Result;
|
||||||
|
use wchat\wx\SmallProgram;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Cash_Bonus
|
||||||
|
* @package wchat\qq
|
||||||
|
*/
|
||||||
|
class Cash_Bonus extends SmallProgram
|
||||||
|
{
|
||||||
|
|
||||||
|
public $_cash = '/cgi-bin/hongbao/qpay_hb_mch_send.cgi';
|
||||||
|
|
||||||
|
private $_errors = [
|
||||||
|
'66228701' => '红包个数超出限制',
|
||||||
|
'66228705' => '总金额超出限制',
|
||||||
|
'66228706' => '总金额不足以按最小金额领取每个红包',
|
||||||
|
'66228707' => '商户签名校验失败',
|
||||||
|
'66228708' => '重入??',
|
||||||
|
'66228709' => 'openid转换uin失败',
|
||||||
|
'66228711' => '商户订单中的商户号有误',
|
||||||
|
'66228712' => '商户订单中的日期超过范围',
|
||||||
|
'66228713' => '余额不足',
|
||||||
|
'66228715' => '用户未关注公众号,发送AIO消息失败',
|
||||||
|
'66229716' => '用户禁用公众号,发AIO消息失败'
|
||||||
|
];
|
||||||
|
|
||||||
|
private $_requestParams = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $value
|
||||||
|
*/
|
||||||
|
public function setMchName(string $value)
|
||||||
|
{
|
||||||
|
$this->_requestParams['mch_name'] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $value
|
||||||
|
*/
|
||||||
|
public function setActName(string $value)
|
||||||
|
{
|
||||||
|
$this->_requestParams['act_name'] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $value
|
||||||
|
*/
|
||||||
|
public function setWishing(string $value)
|
||||||
|
{
|
||||||
|
$this->_requestParams['wishing'] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $value
|
||||||
|
*/
|
||||||
|
public function setIconId($value)
|
||||||
|
{
|
||||||
|
$this->_requestParams['icon_id'] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $value
|
||||||
|
*/
|
||||||
|
public function setBannerId($value)
|
||||||
|
{
|
||||||
|
$this->_requestParams['banner_id'] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $mch_billno
|
||||||
|
* @param $openId
|
||||||
|
* @param $price
|
||||||
|
* @return mixed
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
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['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());
|
||||||
|
}
|
||||||
|
return $response->getData('listid');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $mch_billno
|
||||||
|
* @param $openId
|
||||||
|
* @param $price
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function orderConfig($mch_billno, $openId, $price)
|
||||||
|
{
|
||||||
|
$requestParam['charset'] = 1;
|
||||||
|
$requestParam['nonce_str'] = Help::random(32);
|
||||||
|
$requestParam['mch_billno'] = $mch_billno;
|
||||||
|
$requestParam['mch_id'] = $this->getConfig()->getMchId();
|
||||||
|
$requestParam['qqappid'] = $this->getConfig()->getAppid();
|
||||||
|
$requestParam['re_openid'] = $openId;
|
||||||
|
$requestParam['total_amount'] = $price * 100;
|
||||||
|
$requestParam['min_value'] = $price * 100;
|
||||||
|
$requestParam['max_value'] = $price * 100;
|
||||||
|
$requestParam['total_num'] = 1;
|
||||||
|
$requestParam['notify_url'] = $this->getConfig()->getNotifyUrl();
|
||||||
|
|
||||||
|
if (!empty($this->_requestParams) && is_array($this->_requestParams)) {
|
||||||
|
$requestParam = array_merge($requestParam, $this->_requestParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
$requestParam['sign'] = Help::sign($requestParam, $this->getConfig()->getKey(), 'MD5');
|
||||||
|
|
||||||
|
return $requestParam;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function mchOrderNo()
|
||||||
|
{
|
||||||
|
return implode([
|
||||||
|
$this->getConfig()->getMchId(),
|
||||||
|
date('Ymd'),
|
||||||
|
random_int(11, 99),
|
||||||
|
date('His'),
|
||||||
|
random_int(11, 99)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $requestParams
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function validator(array $requestParams)
|
||||||
|
{
|
||||||
|
$notifySign = $requestParams['sign'];
|
||||||
|
unset($requestParams['sign']);
|
||||||
|
$sign = Help::sign($requestParams, $this->getConfig()->getKey(), 'MD5');
|
||||||
|
|
||||||
|
if ($sign !== $notifySign) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,167 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace wchat\qq\pay;
|
||||||
|
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use wchat\common\Help;
|
||||||
|
use wchat\common\HttpClient;
|
||||||
|
use wchat\common\Result;
|
||||||
|
use wchat\qq\SmallProgram;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Enterprise_payment
|
||||||
|
* @package wchat\qq\pay
|
||||||
|
*/
|
||||||
|
class Enterprise_payment extends SmallProgram
|
||||||
|
{
|
||||||
|
public $_cash = '/cgi-bin/epay/qpay_epay_b2c.cgi';
|
||||||
|
|
||||||
|
private $_errors = [
|
||||||
|
'SYSTEMERROR' => '系统错误',
|
||||||
|
'PARAM_ERROR' => '请求参数未按指引进行填写',
|
||||||
|
'SIGNERROR' => '参数签名结果不正确',
|
||||||
|
'OP_USER_PASSWD_ERROR' => '操作员密码校验失败',
|
||||||
|
'OP_USER_AUTH_ERROR' => '操作员权限错误',
|
||||||
|
'TRANSFER_FEE_LIMIT_ERROR' => '转账限额错误',
|
||||||
|
'TRANSFER_FAIL' => '收款用户的账户不支持收款,收款失败',
|
||||||
|
'NOTENOUGH' => '商户营销账户的余额不足',
|
||||||
|
'ORDERNOTEXIST' => '转账订单不存在',
|
||||||
|
'APPID_OR_OPENID_ERR' => 'appid 或 openid 非法',
|
||||||
|
'TOTAL_FEE_OUT_OF_LIMIT' => '单笔限额检查失败',
|
||||||
|
'SPID_NOT_ALLOW' => '当前商户不支持企业付款',
|
||||||
|
'REALNAME_CHECK_ERROR' => '实名检查失败',
|
||||||
|
'RE_USER_NAME_CHECK_ERROR' => '用户真实姓名校验失败',
|
||||||
|
'INVALID_CERTIFICATE' => '证书非法',
|
||||||
|
];
|
||||||
|
|
||||||
|
private $_requestParams = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $value
|
||||||
|
*/
|
||||||
|
public function setOpUserId(string $value)
|
||||||
|
{
|
||||||
|
$this->_requestParams['op_user_id'] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $value
|
||||||
|
*/
|
||||||
|
public function setOpUserPassword(string $value)
|
||||||
|
{
|
||||||
|
$this->_requestParams['op_user_passwd'] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $value
|
||||||
|
*/
|
||||||
|
public function setSpbillCreateIp(string $value)
|
||||||
|
{
|
||||||
|
$this->_requestParams['spbill_create_ip'] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $mch_billno
|
||||||
|
* @param $openId
|
||||||
|
* @param $price
|
||||||
|
* @return mixed
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
return $response->getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $mch_billno
|
||||||
|
* @param $openId
|
||||||
|
* @param $price
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function orderConfig($mch_billno, $openId, $price)
|
||||||
|
{
|
||||||
|
$requestParam['input_charset'] = 'UTF-8';
|
||||||
|
$requestParam['nonce_str'] = Help::random(32);
|
||||||
|
$requestParam['out_trade_no'] = $mch_billno;
|
||||||
|
$requestParam['mch_id'] = $this->getConfig()->getMchId();
|
||||||
|
$requestParam['appid'] = $this->getConfig()->getAppid();
|
||||||
|
$requestParam['openid'] = $openId;
|
||||||
|
$requestParam['fee_type'] = 'CNY';
|
||||||
|
$requestParam['total_fee'] = $price * 100;
|
||||||
|
$requestParam['memo'] = $this->getConfig()->getBody();
|
||||||
|
$requestParam['notify_url'] = $this->getConfig()->getNotifyUrl();
|
||||||
|
$requestParam['spbill_create_ip'] = $this->getConfig()->getNotifyUrl();
|
||||||
|
|
||||||
|
if (!empty($this->_requestParams) && is_array($this->_requestParams)) {
|
||||||
|
$requestParam = array_merge($requestParam, $this->_requestParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
$requestParam['sign'] = Help::sign($requestParam, $this->getConfig()->getKey(), 'MD5');
|
||||||
|
|
||||||
|
return $requestParam;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function mchOrderNo()
|
||||||
|
{
|
||||||
|
return implode([
|
||||||
|
$this->getConfig()->getMchId(),
|
||||||
|
date('Ymd'),
|
||||||
|
random_int(11, 99),
|
||||||
|
date('His'),
|
||||||
|
random_int(11, 99)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $requestParams
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function validator(array $requestParams)
|
||||||
|
{
|
||||||
|
$notifySign = $requestParams['sign'];
|
||||||
|
unset($requestParams['sign']);
|
||||||
|
$sign = Help::sign($requestParams, $this->getConfig()->getKey(), 'MD5');
|
||||||
|
|
||||||
|
if ($sign !== $notifySign) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user