94 lines
2.7 KiB
PHP
Executable File
94 lines
2.7 KiB
PHP
Executable File
<?php
|
||
|
||
namespace app\admin\controller;
|
||
|
||
use think\facade\Db;
|
||
use think\paginate;
|
||
use think\facade\Request;
|
||
use app\common\model\Withdraw as WithdrawModel;
|
||
use app\common\model\User;
|
||
use think\facade\View;
|
||
|
||
class Withdraw extends Base
|
||
{
|
||
|
||
|
||
|
||
//xml 转换成数组
|
||
|
||
private function createNonceStr($length = 16)
|
||
{
|
||
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||
$str = "";
|
||
for ($i = 0; $i < $length; $i++) {
|
||
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
|
||
}
|
||
return $str;
|
||
}
|
||
|
||
//订单号
|
||
|
||
public function arrayToXml($arr)
|
||
{
|
||
$xml = "<xml>";
|
||
foreach ($arr as $key => $val) {
|
||
if (is_numeric($val)) {
|
||
$xml .= "<" . $key . ">" . $val . "</" . $key . ">";
|
||
} else {
|
||
$xml .= "<" . $key . "><![CDATA[" . $val . "]]></" . $key . ">";
|
||
}
|
||
}
|
||
$xml .= "</xml>";
|
||
return $xml;
|
||
}
|
||
|
||
//获取随机字符串
|
||
|
||
/**
|
||
* 作用:使用证书,以post方式提交xml到对应的接口url
|
||
*/
|
||
public function curl_post_ssl($url, $vars, $second = 30)
|
||
{
|
||
$ch = curl_init();//超时时间curl_setopt($ch,CURLOPT_TIMEOUT,$second);
|
||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||
curl_setopt($ch, CURLOPT_URL, $url);
|
||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||
//以下两种方式需选择一种
|
||
/******* 此处必须为文件服务器根目录绝对路径 不可使用变量代替*********/
|
||
curl_setopt($ch, CURLOPT_SSLCERT, ROOT_PATH . "/public/cert/apiclient_cert.pem");
|
||
curl_setopt($ch, CURLOPT_SSLKEY, ROOT_PATH . "/public/cert/apiclient_key.pem");
|
||
curl_setopt($ch, CURLOPT_POST, 1);
|
||
curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
|
||
$data = curl_exec($ch);
|
||
if ($data) {
|
||
curl_close($ch);
|
||
return $data;
|
||
} else {
|
||
$error = curl_errno($ch);
|
||
echo "call faild, errorCode:$error\n";
|
||
curl_close($ch);
|
||
return false;
|
||
}
|
||
}
|
||
|
||
//数组转xml
|
||
|
||
private function xml_to_array($xml)
|
||
{
|
||
//禁止引用外部 xml 实体
|
||
libxml_disable_entity_loader(true);
|
||
$xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
|
||
$val = json_decode(json_encode($xmlstring), true);
|
||
return $val;
|
||
}
|
||
|
||
|
||
//使用证书,以post方式提交xml到对应的接口url
|
||
|
||
public function ordernum($uid)
|
||
{
|
||
$order = "S" . date("ymdHis", time()) . sprintf("%04d", $uid) . rand(1111, 9999);
|
||
return $order;
|
||
}
|
||
} |