// +---------------------------------------------------------------------- // 应用公共文件 /*app用 * 20210927 * wj */ function backjson3($code, $msg = "", $data = [], $type = 320) { $jsonData = [ 'code' => $code, 'msg' => $msg, 'data' => $data, ]; return json($jsonData); } /* /*app用 * 20210927 * wj */ function backjson2($code, $msg = "", $data = [], $type = 320) { $jsonData = [ 'code' => $code, 'msg' => $msg, 'data' => $data, ]; return json_encode($jsonData, $type); } /* 内部使用 * 20210927 * wj */ function backarr($status, $msg = "", $data = []) { $backData = [ 'status' => $status, 'msg' => $msg, 'data' => $data, ]; return $backData; } /** * 获取星期几 * * @param string $day * @param integer $type * @return void * @author wj * @date 2022-12-02 */ function getweek($day = '', $type = 1) { $weekarr = [7, 1, 2, 3, 4, 5, 6]; if (empty($day)) { $day = time(); } else { switch ($type) { case 1: $day = strtotime($day); break; } } $date = date('w', $day); return $weekarr[$date]; } /** * 数组转xml * * @param [type] $arr * @param [type] $xml * @param string $root * @return void * @author wj * @date 2022-12-02 */ function arrtoxml($arr, $xml = null, $root = '') { if (empty($xml)) { header("Content-type:text/xml;Charset=UTF-8"); $xml = new XMLWriter(); $xml->openMemory(); //$xml->startDocument('1.0', 'UTF-8'); if (!empty($root)) { $xml->startElement($root); } else { $xml->setIndent(true); } arrtoxml($arr, $xml); if (!empty($root)) { $xml->endElement(); } $xml->endDocument(); return $xml->outputMemory(true); } else { if (is_array($arr)) { foreach ($arr as $key => $value) { if (is_array($value)) { $xml->startElement($key); arrtoxml($value, $xml); $xml->endElement(); } else { if (is_numeric($value)) { $xml->writeElement($key, $value); } else { $xml->startElement($key); $xml->writeCdata($value); $xml->endElement(); } } } } } } /** * xml转数组 * * @return void * @author wj * @date 2022-12-02 */ function xmltoarr($xml) { $arr = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); $arr = json_decode(json_encode($arr), true); return $arr; } //为cp后台请求验证token function checkToken() { $l_w = new app\admin\logic\webmanger(); $token = request()->server('HTTP_TOKEN'); if (empty($token)) { $token = request()->param('token'); } $param = ['token' => $token]; $result = $l_w->queryinfobytoken($param); if (1 != $result['status']) { $str = backjson2(0, '登录失效', $result['data']); exit($str); } return $result['data']; } //判断是否是手机号 function isMoblid($tel) { if (preg_match("/^1[3-9]{1}\d{9}$/", $tel)) { return true; } else { return false; } } //curl 请求 function curl_request($url, $data = null, $header = []) { //$headerArray = array("Content-type:application/json;charset='utf-8'", "Accept:application/json"); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, 30); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_HTTPHEADER, $header); if (!empty($data)) { curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); } $output = curl_exec($curl); curl_close($curl); $res = json_decode($output, true); return $res; }