eee
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace wchat\wx\V2;
|
||||
|
||||
use Kiri\Client;
|
||||
use wchat\common\Help;
|
||||
use wchat\common\Result;
|
||||
use wchat\wx\SmallProgram;
|
||||
|
||||
class WxV2Withdrawal extends SmallProgram
|
||||
{
|
||||
|
||||
private string $transfers = '/mmpaymkttransfers/promotion/transfers';
|
||||
|
||||
/**
|
||||
* @param int|float $money
|
||||
* @param string $openid
|
||||
* @param string $order
|
||||
* @param string $desc
|
||||
* @return Result
|
||||
*/
|
||||
public function payment(int|float $money, string $openid, string $order, string $desc = '零钱提现'): Result
|
||||
{
|
||||
$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);
|
||||
|
||||
$client = new Client('api.mch.weixin.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
$client->withBody($body = Help::toXml($array));
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
$client->post($this->transfers);
|
||||
$client->close();
|
||||
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
|
||||
$data = Help::toArray($client->getBody());
|
||||
|
||||
$data['body'] = $body;
|
||||
if ($data['return_code'] == 'FAIL') {
|
||||
return new Result(code: $array['return_code'], message: $data['return_msg'], data: $data);
|
||||
} else if ($array['result_code'] != 'SUCCESS') {
|
||||
return new Result(code: $array['err_code'], message: $data['err_code_des'], data: $data);
|
||||
} else {
|
||||
return new Result(code: 0, message: '提现成功', data: $data);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user