add clear

This commit is contained in:
as2252258@163.com
2019-07-17 17:17:37 +08:00
parent 6e12764656
commit 9c6b01fc94
13 changed files with 1323 additions and 477 deletions
+49 -44
View File
@@ -8,24 +8,25 @@
namespace wchat;
class Recharge extends Base
class Recharge extends Miniprogarampage
{
/** @var Recharge */
private static $recharge;
private $money = 0;
private $orderNo;
private $data = [];
private $transfers = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers';
private $unifiedorder = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
/**
* @param int $money
* @param string $orderNo
* @return bool|Result
* @param string $openId
* @return array|mixed|Result
* @throws
*/
public function payment(int $money, string $orderNo, $openId = NULL)
public function recharge(int $money, string $orderNo, $openId = '')
{
if ($money < 0) {
return new Result(['code' => 500, 'message' => '充值金额不能小于0.']);
@@ -34,14 +35,8 @@ class Recharge extends Base
$this->orderNo = $orderNo;
$this->data['openid'] = $openId;
$params = [
$this->mch_host . '/pay/unifiedorder',
$this->builder(),
[$this, 'payCallback'],
['Content-Type' => 'text/xml']
];
return WxClient::post(...$params);
$this->request->setCallback([$this, 'payCallback']);
return $this->send($this->unifiedorder, $this->builder());
}
@@ -56,20 +51,19 @@ class Recharge extends Base
if (isset($data['sign'])) {
$sign = $data['sign'];
unset($data['sign']);
$_sign = Help::sign($data, $this->key, $this->sign_type);
}
$return = [];
$_sign = Help::sign($data, $this->config->getKey(), $this->config->getSignType());
if (!isset($sign) || $sign != $_sign) {
$return['code'] = -1;
$return['message'] = $data['return_msg'] ?? '返回数据签名验证失败';
} else {
$return['code'] = 0;
$return['data'] = $data;
$return['data']['postBody'] = $body;
if ($data['return_code'] == 'FAIL') {
$return['code'] = -1;
$return['message'] = $data['return_msg'];
} else {
$return['code'] = 0;
$return['data'] = $data;
$return['data']['postBody'] = $body;
}
}
return $return;
@@ -82,22 +76,24 @@ class Recharge extends Base
protected function builder()
{
$data = [
'appid' => $this->appid,
'mch_id' => $this->mch_id,
'nonce_str' => $this->random(32),
'body' => $this->body,
'appid' => $this->config->getAppid(),
'mch_id' => $this->config->getMchId(),
'nonce_str' => Help::random(32),
'body' => $this->config->getBody(),
'out_trade_no' => $this->orderNo,
'total_fee' => $this->money,
'sign_type' => $this->sign_type,
'sign_type' => $this->config->getSignType(),
'spbill_create_ip' => $_SERVER['REMOTE_ADDR'],
'notify_url' => $this->notify_url,
'trade_type' => $this->trade_type,
'notify_url' => $this->config->getNotifyUrl(),
'trade_type' => $this->config->getTradeType(),
];
$data = array_merge($data, $this->data);
$data['sign'] = Help::sign($data, $this->key, $this->sign_type);
$key = $this->config->getKey();
$sign_type = $this->config->getSignType();
$data['sign'] = Help::sign($data, $key, $sign_type);
return Help::toXml($data);
}
@@ -105,38 +101,47 @@ class Recharge extends Base
* @param $money
* @param $openid
* @param $order
* @param $REMOTE_ADDR
* @param $desc
* @return Result
* @throws
*
* 提现
*/
public function tx($money, $openid, $order, $REMOTE_ADDR, $desc = NULL)
public function cashWithdrawal($money, $openid, $order, $desc = '零钱提现')
{
$array = [
'nonce_str' => $this->random(32),
'nonce_str' => Help::random(32),
'partner_trade_no' => $order,
'mchid' => $this->mch_id,
'mch_appid' => $this->appid,
'mchid' => $this->config->getMchId(),
'mch_appid' => $this->config->getAppid(),
'openid' => $openid,
'check_name' => 'NO_CHECK',
'amount' => $money * 100,
'spbill_create_ip' => $REMOTE_ADDR,
'desc' => $desc ?? '有大佬给你发红包啦 . ',
'spbill_create_ip' => $this->config->getRemoteAddr(),
'desc' => $desc,
];
$array['sign'] = Help::sign($array, $this->key, $this->sign_type);
$prams = [
$this->mch_host . '/mmpaymkttransfers/promotion/transfers',
Help::toXml($array),
[$this, 'txCallback'],
NULL,
[$this->ssl_cert, $this->ssl_key]
];
$key = $this->config->getKey();
$sign_type = $this->config->getSignType();
$array['sign'] = Help::sign($array, $key, $sign_type);
return WxClient::post(...$prams);
$this->request->setCallback([$this, 'txCallback']);
return $this->send($this->transfers, Help::toXml($array));
}
/**
* @param $url
* @param $data
* @return array|mixed|Result
* @throws \Exception
*/
private function send($url, $data)
{
$this->request->setIsSSL(true);
$this->request->setMethod(WxClient::POST);
$this->request->addHeader('Content-Type', 'text/xml');
return $this->request->send($url, $data);
}
/**
* @param $data