add clear
This commit is contained in:
-185
@@ -1,185 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: whwyy
|
||||
* Date: 2018/3/26 0026
|
||||
* Time: 10:22
|
||||
*/
|
||||
|
||||
namespace qq;
|
||||
|
||||
use common\HttpClient;
|
||||
use common\Result;
|
||||
use common\Help;
|
||||
|
||||
class Recharge extends SmallProgram
|
||||
{
|
||||
private $money = 0;
|
||||
|
||||
private $orderNo;
|
||||
|
||||
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';
|
||||
|
||||
/**
|
||||
* @param int $money
|
||||
* @param string $orderNo
|
||||
* @param string $openId
|
||||
* @return array|mixed|Result
|
||||
* @throws
|
||||
*/
|
||||
public function recharge(int $money, string $orderNo, $openId = '')
|
||||
{
|
||||
if ($money < 0) {
|
||||
return new Result(['code' => 500, 'message' => '充值金额不能小于0.']);
|
||||
}
|
||||
$this->money = $money;
|
||||
$this->orderNo = $orderNo;
|
||||
$this->data['openid'] = $openId;
|
||||
|
||||
$config = $this->config;
|
||||
$this->request->setCallback(function ($result, $body) use ($config) {
|
||||
$data = Help::toArray($result);
|
||||
if (isset($data['sign'])) {
|
||||
$sign = $data['sign'];
|
||||
unset($data['sign']);
|
||||
}
|
||||
|
||||
$return = [];
|
||||
// $_sign = Help::sign($data, $config->getKey(), $config->getSignType());
|
||||
if (!isset($sign)) {
|
||||
$return['code'] = -1;
|
||||
$return['message'] = '返回数据签名验证失败';
|
||||
// } else if ($sign != $_sign) {
|
||||
// $return['code'] = 401;
|
||||
// $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->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
|
||||
*/
|
||||
protected function builder()
|
||||
{
|
||||
$data = [
|
||||
'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,
|
||||
'spbill_create_ip' => $_SERVER['REMOTE_ADDR'],
|
||||
'notify_url' => $this->config->getNotifyUrl(),
|
||||
'trade_type' => $this->config->getTradeType(),
|
||||
];
|
||||
|
||||
$this->data = array_merge($data, $this->data);
|
||||
|
||||
$key = $this->config->getKey();
|
||||
$sign_type = $this->config->getSignType();
|
||||
|
||||
$this->data['sign_type'] = $this->config->getSignType();
|
||||
$this->data['sign'] = Help::sign($this->data, $key, $sign_type);
|
||||
|
||||
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 $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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user