# PHP
# 代码示例
<?php
$post_url = "https://api.yazx.com/zhbpro/phone_no_check/v2";
$snuser = "XXX";
$snkey = "XXX";
function aes256cfb_encrypt($phoneno) {
global $snkey;
$remainder = strlen($phoneno) % 16;
if ($remainder) {
$plain_text = $phoneno . str_repeat('\0', 16 - $remainder);
} else {
$plain_text = $phoneno;
}
$iv = openssl_random_pseudo_bytes(16);
$value = openssl_encrypt($plain_text, 'AES-256-CFB', $snkey, OPENSSL_RAW_DATA, $iv);
$cipher_text = base64_encode($iv . substr($value, 0, strlen($phoneno)));
return $cipher_text;
}
function aes256cfb_decrypt($phoneno) {
global $snkey;
$data = base64_decode($phoneno);
$cipher_text = substr($data, 16, strlen($data));
$remainder = strlen($cipher_text) % 16;
if ($remainder) {
$cipher = $cipher_text . str_repeat('\0', 16 - $remainder);
} else {
$cipher = $cipher_text;
}
$iv = substr($data, 0, 16);
$plain_text = openssl_decrypt($cipher, 'AES-256-CFB', $snkey, OPENSSL_RAW_DATA, $iv);
return substr($plain_text, 0, strlen($cipher_text));
}
function test($userlist) {
global $snuser, $post_url;
$users = array();
foreach ($userlist as &$user) {
array_push($users, array('user'=>sha1($user)));
}
$pstr = json_encode($users);
$cstr = aes256cfb_encrypt($pstr);
$payload = json_encode(array('snuser'=>$snuser, 'data'=>$cstr), JSON_UNESCAPED_SLASHES);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $post_url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $payload,
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
$res = json_decode($response, true);
if ($res["status"] == 200){
print(aes256cfb_decrypt($res["data"]));
}
else {
print($response);
}
}
$userlist = array("15118376562","13520438342", "13900100033");
test($userlist);
?>;