目錄
1、支付寶自動提現代碼
<?php
/**
* Created by PhpStorm.
* User: bianenhui
* Date: 2019/10/14
* Time: 16:32
*/
class DesUtils
{
private $des3key; // 密鑰向量
private $iv; // 混淆向量
private $mode = MCRYPT_MODE_CBC;
/**
* 構造,傳遞⼆個已經進⾏base64_encode的KEY與IV
*
* @param string $des3key
* @param string $iv
*/
function __construct($des3key, $iv = null)
{
$this->des3key = $des3key;
$this->iv = $iv;
}
/**
* 加密
* @param <type> $value
* @return <type>
*/
public function encrypt($value)
{
$td = mcrypt_module_open(MCRYPT_3DES, '', $this->mode, '');
$iv = substr($this->des3key, 0, 8);
$value = $this->PaddingPKCS7($value);
@mcrypt_generic_init($td, $this->des3key, $iv);
$dec = mcrypt_generic($td, $value);
$ret = base64_encode($dec);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return $ret;
}
/**
* 解密
* @param <type> $value
* @return <type>
*/
public function decrypt($value)
{
$td = mcrypt_module_open(MCRYPT_3DES, '', $this->mode, '');
$iv = substr($this->des3key, 0, 8);
@mcrypt_generic_init($td, $this->des3key, $iv);
$ret = trim(mdecrypt_generic($td, base64_decode($value)));
$ret = $this->UnPaddingPKCS7($ret);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return $ret;
}
private function PaddingPKCS7($data)
{
$block_size = mcrypt_get_block_size('tripledes', $this->mode);
$padding_char = $block_size - (strlen($data) % $block_size);
$data .= str_repeat(chr($padding_char), $padding_char);
return $data;
}
private function UnPaddingPKCS7($text)
{
$pad = ord($text{strlen($text) - 1});
if ($pad > strlen($text)) {
return false;
}
if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) {
return false;
}
return substr($text, 0, -1 * $pad);
}
}
$info = [
"order_id" => "201910141637".time(),
"dealer_id" => "285114213",
"broker_id" => "27532144",
"real_name" => "張三",
"id_card" => "342522188005052140",
"card_no" => "13000000000",
"pay" => "1.00",
"pay_remark" => "",
"check_name" => "NoCheck",
"notify_url" => "",
];
$des3key = 'hx4b3sdn32z22T3Q5n862v21';
$appkey = "HFrn2i2W3Eo56m2Fh3I7XX34JAEKvwNk";
$json_data = json_encode($info);
$DesUtilsObj = new DesUtils($des3key);
$data = $DesUtilsObj->encrypt($json_data);
$mess = time();
$timestamp = time();
$key_sign = "data=".$data."&mess=".$mess."×tamp=".$timestamp."&key=".$appkey;
$key_sign1 = "data=".$data."&mess=".$mess."&timestamp=".$timestamp."&key=".$appkey;
$sign = hash_hmac('sha256', $key_sign, $appkey);
$sign_type = "sha256";
$postUrl = 'https://api-jiesuan.yunzhanghu.com/api/payment/v1/order-alipay';
$postData = array(
'dealer-id' => '28511713',
'request-id' => "20191015".time().time(),
'data' => $data,
'mess' => $mess,
'timestamp' => $timestamp,
'sign' => $sign,
'sign_type' => $sign_type,
);
$header = [
'Content-Type:application/x-www-form-urlencoded',
'dealer-id:28511713',
];
$postData = http_build_query($postData);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $postUrl);
curl_setopt($curl, CURLOPT_USERAGENT,'Opera/9.80 (Windows NT 6.2; Win64; x64) Presto/2.12.388 Version/12.15');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // stop verifying certificate
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
$r = curl_exec($curl);
curl_close($curl);
print_r($r);
2、銀行卡自動提現代碼
<?php
/**
* Created by PhpStorm.
* User: bianenhui
* Date: 2019/10/14
* Time: 16:32
*/
class DesUtils
{
private $des3key; // 密鑰向量
private $iv; // 混淆向量
private $mode = MCRYPT_MODE_CBC;
/**
* 構造,傳遞⼆個已經進⾏base64_encode的KEY與IV
*
* @param string $des3key
* @param string $iv
*/
function __construct($des3key, $iv = null)
{
$this->des3key = $des3key;
$this->iv = $iv;
}
/**
* 加密
* @param <type> $value
* @return <type>
*/
public function encrypt($value)
{
$td = mcrypt_module_open(MCRYPT_3DES, '', $this->mode, '');
$iv = substr($this->des3key, 0, 8);
$value = $this->PaddingPKCS7($value);
@mcrypt_generic_init($td, $this->des3key, $iv);
$dec = mcrypt_generic($td, $value);
$ret = base64_encode($dec);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return $ret;
}
/**
* 解密
* @param <type> $value
* @return <type>
*/
public function decrypt($value)
{
$td = mcrypt_module_open(MCRYPT_3DES, '', $this->mode, '');
$iv = substr($this->des3key, 0, 8);
@mcrypt_generic_init($td, $this->des3key, $iv);
$ret = trim(mdecrypt_generic($td, base64_decode($value)));
$ret = $this->UnPaddingPKCS7($ret);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return $ret;
}
private function PaddingPKCS7($data)
{
$block_size = mcrypt_get_block_size('tripledes', $this->mode);
$padding_char = $block_size - (strlen($data) % $block_size);
$data .= str_repeat(chr($padding_char), $padding_char);
return $data;
}
private function UnPaddingPKCS7($text)
{
$pad = ord($text{strlen($text) - 1});
if ($pad > strlen($text)) {
return false;
}
if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) {
return false;
}
return substr($text, 0, -1 * $pad);
}
}
$info = [
"order_id" => "201910141637".time(),
"dealer_id" => "28511713",
"broker_id" => "27532644",
"real_name" => "張三",
"card_no" => "6228880199872220",
"phone_no" => "13488795491",
"id_card" => "5326123123123211",
"pay" => "1.00",
"pay_remark" => "",
"notify_url" => "",
];
$des3key = 'hx4b3sdn62z22TBQ5n862v21';
$appkey = "HFrn2iqW3Eo56m2FhrI7XX34JAEKvwNk";
$json_data = json_encode($info);
$DesUtilsObj = new DesUtils($des3key);
$data = $DesUtilsObj->encrypt($json_data);
$mess = time();
$timestamp = time();
$key_sign = "data=".$data."&mess=".$mess."×tamp=".$timestamp."&key=".$appkey;
$key_sign1 = "data=".$data."&mess=".$mess."&timestamp=".$timestamp."&key=".$appkey;
$sign = hash_hmac('sha256', $key_sign, $appkey);
$sign_type = "sha256";
$postUrl = 'https://api-jiesuan.yunzhanghu.com/api/payment/v1/order-realtime';
$postData = array(
'dealer-id' => '28511313',
'request-id' => "20191015".time().time(),
'data' => $data,
'mess' => $mess,
'timestamp' => $timestamp,
'sign' => $sign,
'sign_type' => $sign_type,
);
$header = [
'Content-Type:application/x-www-form-urlencoded',
'dealer-id:28511713',
];
$postData = http_build_query($postData);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $postUrl);
curl_setopt($curl, CURLOPT_USERAGENT,'Opera/9.80 (Windows NT 6.2; Win64; x64) Presto/2.12.388 Version/12.15');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // stop verifying certificate
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
$r = curl_exec($curl);
curl_close($curl);
print_r($r);