|
@@ -0,0 +1,1076 @@
|
|
|
+<?php
|
|
|
+defined('ONLY_ONLY_ONLY') or exit('Access Denied');
|
|
|
+function crossdomain_cookie_init()
|
|
|
+{
|
|
|
+ $maxlifetime = 0;
|
|
|
+ $secure = true;
|
|
|
+ $httponly = true;
|
|
|
+ $samesite = 'None';
|
|
|
+ if (PHP_VERSION_ID < 70300) {
|
|
|
+ session_set_cookie_params($maxlifetime, '/; samesite=' . $samesite, $_SERVER['HTTP_HOST'], $secure, $httponly);
|
|
|
+ } else {
|
|
|
+ session_set_cookie_params([
|
|
|
+ 'lifetime' => $maxlifetime,
|
|
|
+ 'path' => '/',
|
|
|
+ 'secure' => $secure,
|
|
|
+ 'httponly' => $httponly,
|
|
|
+ 'samesite' => $samesite,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function input_getPostObj()
|
|
|
+{
|
|
|
+ $httpdata = file_get_contents("php://input");
|
|
|
+ $ajaxdata = @json_decode($httpdata, true);
|
|
|
+ if (empty($ajaxdata)) {
|
|
|
+ parse_str($httpdata, $ajaxdata);
|
|
|
+ }
|
|
|
+ return $ajaxdata;
|
|
|
+}
|
|
|
+function base_stripslashes_deep($value)
|
|
|
+{
|
|
|
+ $value = is_array($value) ? array_map('base_stripslashes_deep', $value) : stripslashes($value);
|
|
|
+ return $value;
|
|
|
+}
|
|
|
+function base_irequestsplite($var)
|
|
|
+{
|
|
|
+ if (is_array($var)) {
|
|
|
+ foreach ($var as $key => $value) {
|
|
|
+ $var[htmlspecialchars($key)] = base_irequestsplite($value);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $var = str_replace('&', '&', htmlspecialchars($var, ENT_QUOTES));
|
|
|
+ }
|
|
|
+ return $var;
|
|
|
+}
|
|
|
+function input_param_handle($preHandle = true)
|
|
|
+{
|
|
|
+ $GET = $_GET;
|
|
|
+ $POST = $_POST;
|
|
|
+ $COOKIE = $_COOKIE;
|
|
|
+ $REQUEST = $_REQUEST;
|
|
|
+ if ($preHandle) {
|
|
|
+ $GET = array_map('base_stripslashes_deep', $_GET);
|
|
|
+ $POST = array_map('base_stripslashes_deep', $_POST);
|
|
|
+ $COOKIE = array_map('base_stripslashes_deep', $_COOKIE);
|
|
|
+ $REQUEST = array_map('base_stripslashes_deep', $_REQUEST);
|
|
|
+ }
|
|
|
+ $_GPC = array();
|
|
|
+ $_GPC = array_merge($GET, $POST, $_GPC);
|
|
|
+ if ($preHandle) {
|
|
|
+ $_GPC = base_irequestsplite($_GPC);
|
|
|
+ }
|
|
|
+ return $_GPC;
|
|
|
+}
|
|
|
+function input_file_errhandle($filectl)
|
|
|
+{
|
|
|
+ $fileerror = intval($filectl["error"]);
|
|
|
+ if ($fileerror > 0) {
|
|
|
+ switch ($fileerror) {
|
|
|
+ case 1: //UPLOAD_ERR_INI_SIZE
|
|
|
+ $err_msg = "上传的文件超过了 php.ini 中 upload_max_filesize选项限制的值";
|
|
|
+ break;
|
|
|
+ case 2: //UPLOAD_ERR_FORM_SIZE
|
|
|
+ $err_msg = "上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值";
|
|
|
+ break;
|
|
|
+ case 3: //UPLOAD_ERR_PARTIAL
|
|
|
+ $err_msg = "文件只有部分被上传";
|
|
|
+ break;
|
|
|
+ case 4: //UPLOAD_ERR_NO_FILE
|
|
|
+ $err_msg = "文件没有被上传";
|
|
|
+ break;
|
|
|
+ case 5: //UPLOAD_ERR_NO_TMP_DIR
|
|
|
+ $err_msg = "找不到临时文件夹";
|
|
|
+ break;
|
|
|
+ case 6: //UPLOAD_ERR_CANT_WRITE
|
|
|
+ $err_msg = "文件写入失败";
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ $err_msg = "未知错误";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ throw new Exception("上传失败:" . $err_msg);
|
|
|
+ }
|
|
|
+}
|
|
|
+function input_file_upload($filectl_name, $subdir, $filename = "", $maxsize = 10 * 1024 * 1024, $filetypes = "jpg|png|jpeg|gif")
|
|
|
+{
|
|
|
+ if (!isset($_FILES[$filectl_name])) {
|
|
|
+ $GPC = input_param_handle(false);
|
|
|
+ $ajaxdata = input_getPostObj();
|
|
|
+ $tmpfilectl_name = isset($ajaxdata[$filectl_name]) ? $ajaxdata[$filectl_name] : $GPC[$filectl_name];
|
|
|
+ if (empty($tmpfilectl_name) || !isset($_FILES[$tmpfilectl_name])) {
|
|
|
+ throw new GeneralException("", "没有定位到文件控件或文件内容为空,请核查!!");
|
|
|
+ }
|
|
|
+
|
|
|
+ $filectl_name = $tmpfilectl_name;
|
|
|
+ }
|
|
|
+ $filectl = $_FILES[$filectl_name];
|
|
|
+ input_file_errhandle($filectl);
|
|
|
+ $filetype = $filectl["type"];
|
|
|
+ $filesize = $filectl["size"];
|
|
|
+ if ($filesize > $maxsize) {
|
|
|
+ throw new GeneralException("", "上传失败:文件不能超过" . ($maxsize / 1024) . "KB,请您核查一下是否上传错了:)");
|
|
|
+ }
|
|
|
+
|
|
|
+ $fileex = pathinfo($filectl["name"])['extension'];
|
|
|
+ if (empty($filetypes) || (mb_strpos($filetypes, strtolower($fileex) . "|") !== false)) {
|
|
|
+ $dest_urldir = WEB_URL_FILEROOT . (empty($subdir) ? "" : "/" . $subdir);
|
|
|
+ $dest_phydir = WEB_PHY_FILEROOT . (empty($subdir) ? "" : "/" . $subdir);
|
|
|
+ is_dir($dest_phydir) or mkdir($dest_phydir, 0755, false);
|
|
|
+ if (empty($filename)) {
|
|
|
+ do {
|
|
|
+ $filename = 'file_' . rand(123456, 9999) . "." . $fileex;
|
|
|
+ $file_relative_path = $dest_urldir . "/" . $filename;
|
|
|
+ $file_physical_path = $dest_phydir . "/" . $filename;
|
|
|
+ } while (is_file($file_physical_path));
|
|
|
+ } else {
|
|
|
+ $file_relative_path = $dest_urldir . "/" . $filename;
|
|
|
+ $file_physical_path = $dest_phydir . "/" . $filename;
|
|
|
+ }
|
|
|
+ $filetmp_name = $filectl["tmp_name"];
|
|
|
+ if (move_uploaded_file($filetmp_name, $file_physical_path)) {
|
|
|
+ } else {
|
|
|
+ throw new GeneralException("", "图片上传保存时失败");
|
|
|
+ }
|
|
|
+ return $file_relative_path;
|
|
|
+ } else {
|
|
|
+ throw new GeneralException("", "上传失败:图片文件只能是" . $filetypes . "格式");
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/*****************/
|
|
|
+function random($length, $numeric = false)
|
|
|
+{
|
|
|
+ $seed = base_convert(md5(microtime() . $_SERVER['DOCUMENT_ROOT']), 16, $numeric ? 10 : 35);
|
|
|
+ $seed = $numeric ? (str_replace('0', '', $seed) . '012340567890') : ($seed . 'zZ' . strtoupper($seed));
|
|
|
+ if ($numeric) {
|
|
|
+ $hash = '';
|
|
|
+ } else {
|
|
|
+ $hash = chr(rand(1, 26) + rand(0, 1) * 32 + 64);
|
|
|
+ $length--;
|
|
|
+ }
|
|
|
+ $max = strlen($seed) - 1;
|
|
|
+ for ($i = 0; $i < $length; $i++) {
|
|
|
+ $hash .= $seed[mt_rand(0, $max)];
|
|
|
+ }
|
|
|
+ return $hash;
|
|
|
+}
|
|
|
+
|
|
|
+/******http通信处理******/
|
|
|
+function http_post($url, $header = array(), $post_data, $withpem = false, $client_cert_pem = '', $client_cert_key = '', $cert_pwd = '')
|
|
|
+{
|
|
|
+ $ch = curl_init();
|
|
|
+ curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
|
|
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
+ curl_setopt($ch, CURLOPT_TIMEOUT, 10); //10秒超时
|
|
|
+ curl_setopt($ch, CURLOPT_POST, 1);
|
|
|
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
|
|
|
+ curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1');
|
|
|
+ if ($withpem) { //证书相关
|
|
|
+ curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'PEM');
|
|
|
+ curl_setopt($ch, CURLOPT_SSLCERT, '' . $client_cert_pem . '');
|
|
|
+ curl_setopt($ch, CURLOPT_SSLKEYTYPE, 'PEM');
|
|
|
+ curl_setopt($ch, CURLOPT_SSLKEY, '' . $client_cert_key . '');
|
|
|
+ curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $cert_pwd);
|
|
|
+ curl_setopt($ch, CURLOPT_KEYPASSWD, $cert_pwd);
|
|
|
+ }
|
|
|
+ $data = curl_exec($ch);
|
|
|
+ $error_no = curl_errno($ch);
|
|
|
+ $err_msg = "";
|
|
|
+ curl_close($ch);
|
|
|
+ if (!empty($error_no)) {
|
|
|
+ $err_msg = http_curl_geterr($error_no);
|
|
|
+ eeglobal_log_handler('http_post', 'error', "http_post通信异常 err_msg=>$err_msg result=>$data");
|
|
|
+ throw new GeneralException("http_post", "http_post通信异常");
|
|
|
+ }
|
|
|
+ return $data;
|
|
|
+}
|
|
|
+function http_get($url, $header = array())
|
|
|
+{
|
|
|
+ $ch = curl_init();
|
|
|
+ curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
|
|
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
+ curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
|
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
+ curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1');
|
|
|
+ $data = curl_exec($ch);
|
|
|
+ $error_no = curl_errno($ch);
|
|
|
+ $err_msg = "";
|
|
|
+ curl_close($ch);
|
|
|
+ if (!empty($error_no)) {
|
|
|
+ $err_msg = http_curl_geterr($error_no);
|
|
|
+ eeglobal_log_handler('http_get', 'error', "http_get通信异常 err_msg=>$err_msg result=>$data");
|
|
|
+ throw new GeneralException("http_get", 'http_get通信异常');
|
|
|
+ }
|
|
|
+ return $data;
|
|
|
+}
|
|
|
+function http_curl_geterr($no)
|
|
|
+{
|
|
|
+ $error_codes = array(
|
|
|
+ '1' => 'CURLE_UNSUPPORTED_PROTOCOL (1) – 您传送给 libcurl 的网址使用了此 libcurl 不支持的协议。 可能是您没有使用的编译时选项造成了这种情况(可能是协议字符串拼写有误,或没有指定协议 libcurl 代码)。',
|
|
|
+ '2' => 'CURLE_FAILED_INIT (2) – 非常早期的初始化代码失败。 可能是内部错误或问题。',
|
|
|
+ '3' => 'CURLE_URL_MALFORMAT (3) – 网址格式不正确。',
|
|
|
+ '5' => 'CURLE_COULDNT_RESOLVE_PROXY (5) – 无法解析代理服务器。 指定的代理服务器主机无法解析。',
|
|
|
+ '6' => 'CURLE_COULDNT_RESOLVE_HOST (6) – 无法解析主机。 指定的远程主机无法解析。',
|
|
|
+ '7' => 'CURLE_COULDNT_CONNECT (7) – 无法通过 connect() 连接至主机或代理服务器。',
|
|
|
+ '8' => 'CURLE_FTP_WEIRD_SERVER_REPLY (8) – 在连接到 FTP 服务器后,libcurl 需要收到特定的回复。 此错误代码表示收到了不正常或不正确的回复。 指定的远程服务器可能不是正确的 FTP 服务器。',
|
|
|
+ '9' => 'CURLE_REMOTE_ACCESS_DENIED (9) – 我们无法访问网址中指定的资源。 对于 FTP,如果尝试更改为远程目录,就会发生这种情况。',
|
|
|
+ '11' => 'CURLE_FTP_WEIRD_PASS_REPLY (11) – 在将 FTP 密码发送到服务器后,libcurl 需要收到正确的回复。 此错误代码表示返回的是意外的代码。',
|
|
|
+ '13' => 'CURLE_FTP_WEIRD_PASV_REPLY (13) – libcurl 无法从服务器端收到有用的结果,作为对 PASV 或 EPSV 命令的响应。 服务器有问题。',
|
|
|
+ '14' => 'CURLE_FTP_WEIRD_227_FORMAT (14) – FTP 服务器返回 227 行作为对 PASV 命令的响应。如果 libcurl 无法解析此行,就会返回此代码。',
|
|
|
+ '15' => 'CURLE_FTP_CANT_GET_HOST (15) – 在查找用于新连接的主机时出现内部错误。',
|
|
|
+ '17' => 'CURLE_FTP_COULDNT_SET_TYPE (17) – 在尝试将传输模式设置为二进制或 ascii 时发生错误。',
|
|
|
+ '18' => 'CURLE_PARTIAL_FILE (18) – 文件传输尺寸小于或大于预期。当服务器先报告了一个预期的传输尺寸,然后所传送的数据与先前指定尺寸不相符时,就会发生此错误。',
|
|
|
+ '19' => 'CURLE_FTP_COULDNT_RETR_FILE (19) – ‘RETR’ 命令收到了不正常的回复,或完成的传输尺寸为零字节。',
|
|
|
+ '21' => 'CURLE_QUOTE_ERROR (21) – 在向远程服务器发送自定义 “QUOTE” 命令时,其中一个命令返回的错误代码为 400 或更大的数字(对于 FTP),或以其他方式表明命令无法成功完成。',
|
|
|
+ '22' => 'CURLE_HTTP_RETURNED_ERROR (22) – 如果 CURLOPT_FAILONERROR 设置为 TRUE,且 HTTP 服务器返回 >= 400 的错误代码,就会返回此代码。 (此错误代码以前又称为 CURLE_HTTP_NOT_FOUND。)',
|
|
|
+ '23' => 'CURLE_WRITE_ERROR (23) – 在向本地文件写入所收到的数据时发生错误,或由写入回调 (write callback) 向 libcurl 返回了一个错误。',
|
|
|
+ '25' => 'CURLE_UPLOAD_FAILED (25) – 无法开始上传。 对于 FTP,服务器通常会拒绝执行 STOR 命令。错误缓冲区通常会提供服务器对此问题的说明。 (此错误代码以前又称为 CURLE_FTP_COULDNT_STOR_FILE。)',
|
|
|
+ '26' => 'CURLE_READ_ERROR (26) – 读取本地文件时遇到问题,或由读取回调 (read callback) 返回了一个错误。',
|
|
|
+ '27' => 'CURLE_OUT_OF_MEMORY (27) – 内存分配请求失败。此错误比较严重,若发生此错误,则表明出现了非常严重的问题。',
|
|
|
+ '28' => 'CURLE_OPERATION_TIMEDOUT (28) – 操作超时。 已达到根据相应情况指定的超时时间。',
|
|
|
+ '30' => 'CURLE_FTP_PORT_FAILED (30) – FTP PORT 命令返回错误。 在没有为 libcurl 指定适当的地址使用时,最有可能发生此问题。 请参阅 CURLOPT_FTPPORT。',
|
|
|
+ '31' => 'CURLE_FTP_COULDNT_USE_REST (31) – FTP REST 命令返回错误。如果服务器正常,则应当不会发生这种情况。',
|
|
|
+ '33' => 'CURLE_RANGE_ERROR (33) – 服务器不支持或不接受范围请求。',
|
|
|
+ '34' => 'CURLE_HTTP_POST_ERROR (34) – 此问题比较少见,主要由内部混乱引发。',
|
|
|
+ '35' => 'CURLE_SSL_CONNECT_ERROR (35) – 同时使用 SSL/TLS 时可能会发生此错误。您可以访问错误缓冲区查看相应信息,其中会对此问题进行更详细的介绍。可能是证书(文件格式、路径、许可)、密码及其他因素导致了此问题。',
|
|
|
+ '36' => 'CURLE_FTP_BAD_DOWNLOAD_RESUME (36) – 尝试恢复超过文件大小限制的 FTP 连接。',
|
|
|
+ '37' => 'CURLE_FILE_COULDNT_READ_FILE (37) – 无法打开 FILE:// 路径下的文件。原因很可能是文件路径无法识别现有文件。 建议您检查文件的访问权限。',
|
|
|
+ '38' => 'CURLE_LDAP_CANNOT_BIND (38) – LDAP 无法绑定。LDAP 绑定操作失败。',
|
|
|
+ '39' => 'CURLE_LDAP_SEARCH_FAILED (39) – LDAP 搜索无法进行。',
|
|
|
+ '41' => 'CURLE_FUNCTION_NOT_FOUND (41) – 找不到函数。 找不到必要的 zlib 函数。',
|
|
|
+ '42' => 'CURLE_ABORTED_BY_CALLBACK (42) – 由回调中止。 回调向 libcurl 返回了 “abort”。',
|
|
|
+ '43' => 'CURLE_BAD_FUNCTION_ARGUMENT (43) – 内部错误。 使用了不正确的参数调用函数。',
|
|
|
+ '45' => 'CURLE_INTERFACE_FAILED (45) – 界面错误。 指定的外部界面无法使用。 请通过 CURLOPT_INTERFACE 设置要使用哪个界面来处理外部连接的来源 IP 地址。 (此错误代码以前又称为 CURLE_HTTP_PORT_FAILED。)',
|
|
|
+ '47' => 'CURLE_TOO_MANY_REDIRECTS (47) – 重定向过多。 进行重定向时,libcurl 达到了网页点击上限。请使用 CURLOPT_MAXREDIRS 设置上限。',
|
|
|
+ '48' => 'CURLE_UNKNOWN_TELNET_OPTION (48) – 无法识别以 CURLOPT_TELNETOPTIONS 设置的选项。 请参阅相关文档。',
|
|
|
+ '49' => 'CURLE_TELNET_OPTION_SYNTAX (49) – telnet 选项字符串的格式不正确。',
|
|
|
+ '51' => 'CURLE_PEER_FAILED_VERIFICATION (51) – 远程服务器的 SSL 证书或 SSH md5 指纹不正确。',
|
|
|
+ '52' => 'CURLE_GOT_NOTHING (52) – 服务器未返回任何数据,在相应情况下,未返回任何数据就属于出现错误。',
|
|
|
+ '53' => 'CURLE_SSL_ENGINE_NOTFOUND (53) – 找不到指定的加密引擎。',
|
|
|
+ '54' => 'CURLE_SSL_ENGINE_SETFAILED (54) – 无法将选定的 SSL 加密引擎设为默认选项。',
|
|
|
+ '55' => 'CURLE_SEND_ERROR (55) – 无法发送网络数据。',
|
|
|
+ '56' => 'CURLE_RECV_ERROR (56) – 接收网络数据失败。',
|
|
|
+ '58' => 'CURLE_SSL_CERTPROBLEM (58) – 本地客户端证书有问题',
|
|
|
+ '59' => 'CURLE_SSL_CIPHER (59) – 无法使用指定的密钥',
|
|
|
+ '60' => 'CURLE_SSL_CACERT (60) – 无法使用已知的 CA 证书验证对等证书',
|
|
|
+ '61' => 'CURLE_BAD_CONTENT_ENCODING (61) – 无法识别传输编码',
|
|
|
+ '62' => 'CURLE_LDAP_INVALID_URL (62) – LDAP 网址无效',
|
|
|
+ '63' => 'CURLE_FILESIZE_EXCEEDED (63) – 超过了文件大小上限',
|
|
|
+ '64' => 'CURLE_USE_SSL_FAILED (64) – 请求的 FTP SSL 级别失败',
|
|
|
+ '65' => 'CURLE_SEND_FAIL_REWIND (65) – 进行发送操作时,curl 必须回转数据以便重新传输,但回转操作未能成功',
|
|
|
+ '66' => 'CURLE_SSL_ENGINE_INITFAILED (66) – SSL 引擎初始化失败',
|
|
|
+ '67' => 'CURLE_LOGIN_DENIED (67) – 远程服务器拒绝 curl 登录(7.13.1 新增功能)',
|
|
|
+ '68' => 'CURLE_TFTP_NOTFOUND (68) – 在 TFTP 服务器上找不到文件',
|
|
|
+ '69' => 'CURLE_TFTP_PERM (69) – 在 TFTP 服务器上遇到权限问题',
|
|
|
+ '70' => 'CURLE_REMOTE_DISK_FULL (70) – 服务器磁盘空间不足',
|
|
|
+ '71' => 'CURLE_TFTP_ILLEGAL (71) – TFTP 操作非法',
|
|
|
+ '72' => 'CURLE_TFTP_UNKNOWNID (72) – TFTP 传输 ID 未知',
|
|
|
+ '73' => 'CURLE_REMOTE_FILE_EXISTS (73) – 文件已存在,无法覆盖',
|
|
|
+ '74' => 'CURLE_TFTP_NOSUCHUSER (74) – 运行正常的 TFTP 服务器不会返回此错误',
|
|
|
+ '75' => 'CURLE_CONV_FAILED (75) – 字符转换失败',
|
|
|
+ '76' => 'CURLE_CONV_REQD (76) – 调用方必须注册转换回调',
|
|
|
+ '77' => 'CURLE_SSL_CACERT_BADFILE (77) – 读取 SSL CA 证书时遇到问题(可能是路径错误或访问权限问题)',
|
|
|
+ '78' => 'CURLE_REMOTE_FILE_NOT_FOUND (78) – 网址中引用的资源不存在',
|
|
|
+ '79' => 'CURLE_SSH (79) – SSH 会话中发生无法识别的错误',
|
|
|
+ '80' => 'CURLE_SSL_SHUTDOWN_FAILED (80) – 无法终止 SSL 连接',
|
|
|
+ '81' => 'CURLE_AGAIN---Socket是没有准备好发送/接收等待,直到它准备好了,然后再试一次。',
|
|
|
+ '82' => 'CURLE_SSL_CRL_BADFILE---无法加载CRL文件(在7.19.0版加入)',
|
|
|
+ '83' => 'CURLE_SSL_ISSUER_ERROR---发行人检查失败(在7.19.0版加入)',
|
|
|
+ '84' => 'CURLE_FTP_PRET_FAILED---FTP服务器不理解的PRET命令,所有不支持给定的参数。要小心时usingCURLOPT_CUSTOMREQUEST,自定义列表“命令将发送PRET CMD前PASV以及。',
|
|
|
+ '85' => 'CURLE_RTSP_CSEQ_ERROR---RTSP的Cseq号码不匹配。',
|
|
|
+ '86' => 'CURLE_RTSP_SESSION_ERROR---RTSP会话标识符不匹配。',
|
|
|
+ '87' => 'CURLE_FTP_BAD_FILE_LIST--无法,解析FTP文件列表(在FTP通配符下载)。',
|
|
|
+ '88' => 'CURLE_CHUNK_FAILED--块回调报告错误。',
|
|
|
+ );
|
|
|
+ if (isset($error_codes[$no])) {
|
|
|
+ return $error_codes[$no];
|
|
|
+ } else {
|
|
|
+ return '通信异常=>' . $no;
|
|
|
+ }
|
|
|
+}
|
|
|
+function oshandle_mkdirs($path)
|
|
|
+{
|
|
|
+ if (!is_dir($path)) {
|
|
|
+ oshandle_mkdirs(dirname($path));
|
|
|
+ if (!empty($path)) {
|
|
|
+ mkdir($path);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return is_dir($path);
|
|
|
+}
|
|
|
+class global_process2lock
|
|
|
+{
|
|
|
+ public static $flockSet = array();
|
|
|
+ public static function lock($fp)
|
|
|
+ {
|
|
|
+ if (empty($fp)) {
|
|
|
+ throw new Exception("锁文件参数为空!");
|
|
|
+ }
|
|
|
+ if (!file_exists($fp)) {
|
|
|
+ throw new Exception("锁文件路径【" . $fp . "】不存在!");
|
|
|
+ }
|
|
|
+ global_process2lock::$flockSet[$fp] = fopen($fp, 'r');
|
|
|
+ if (empty(global_process2lock::$flockSet[$fp])) {
|
|
|
+ throw new Exception(" global_process2lock 未能打开文件 fp=>" . $fp);
|
|
|
+ }
|
|
|
+
|
|
|
+ $flockflag = flock(global_process2lock::$flockSet[$fp], LOCK_EX);
|
|
|
+ if (empty($flockflag)) {
|
|
|
+ throw new Exception(" global_process2lock flock没有能够加上LOCK_EX独占阻塞锁 fp=>" . $fp);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $flockflag;
|
|
|
+ }
|
|
|
+ public static function unlock($fp)
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ if (empty(global_process2lock::$flockSet[$fp])) {
|
|
|
+ throw new Exception(" global_process2lock flock解锁LOCK_UN未成功 fp为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ $resultA = flock(global_process2lock::$flockSet[$fp], LOCK_UN);
|
|
|
+ if (empty($resultA)) {
|
|
|
+ throw new Exception(" global_process2lock flock解锁LOCK_UN未成功 fp=>" . $fp);
|
|
|
+ }
|
|
|
+
|
|
|
+ $resultB = fclose(global_process2lock::$flockSet[$fp]);
|
|
|
+ if (empty($resultB)) {
|
|
|
+ throw new Exception(" global_process2lock fclose释放文件锁未成功 fp=>" . $fp);
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Throwable $ex) {
|
|
|
+ if (true) {
|
|
|
+ eeglobal_log_handler("global_process2lock", 'ERROR', " global_process2lock fp=>" . $fp . " 释放锁时异常=>" . $ex->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+function filelock_handle($lockCatalog, $lockId, $handleArgs, $bizHandle)
|
|
|
+{
|
|
|
+ $logCatalog = "filelock_handle";
|
|
|
+ eeglobal_log_handler($logCatalog, "debug", "enter lockCatalog=$lockCatalog lockId=$lockId");
|
|
|
+ if (empty($lockCatalog)) {
|
|
|
+ throw new GeneralException("", "lockCatalog文件锁类别不能为空!");
|
|
|
+ }
|
|
|
+
|
|
|
+ $lockId = intval($lockId);
|
|
|
+ if ($lockId == 0) {
|
|
|
+ $lockId = "all";
|
|
|
+ }
|
|
|
+//为空则为此业务类别的全局锁,非记录锁
|
|
|
+ $FLCK_PHY_ROOT = WEB_PHY_FILEROOT . "/FILELOCK_ROOT";
|
|
|
+ $lockFile = $FLCK_PHY_ROOT . "/$lockCatalog/FL_$lockId.flk";
|
|
|
+ $destPhyPath = dirname($lockFile);
|
|
|
+ try {
|
|
|
+ if (!is_dir($destPhyPath)) {
|
|
|
+ if (!mkdir($destPhyPath, 0777, true)) {
|
|
|
+ throw new Exception("创建lockId文件锁相关目录时发生错误!");
|
|
|
+ }
|
|
|
+ chmod($destPhyPath, 0777);
|
|
|
+ }
|
|
|
+ if (!file_exists($lockFile)) {
|
|
|
+ if (!fopen($lockFile, "w")) {
|
|
|
+ throw new Exception("创建lockId文件锁文件失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Throwable $e) {
|
|
|
+ throw new GeneralException("", "创建lockId文件锁相关目录及文件时发生错误!" . $e->getMessage());
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ eeglobal_log_handler($logCatalog, "debug", "lockbefore lockCatalog=$lockCatalog lockId=$lockId");
|
|
|
+ global_process2lock::lock($lockFile);
|
|
|
+ eeglobal_log_handler($logCatalog, "debug", "lockafter lockCatalog=$lockCatalog lockId=$lockId");
|
|
|
+ return $bizHandle($handleArgs);
|
|
|
+ } catch (Throwable $ex) {
|
|
|
+ throw $ex;
|
|
|
+ } finally {
|
|
|
+ eeglobal_log_handler($logCatalog, "debug", "unlockbefore lockCatalog=$lockCatalog lockId=$lockId");
|
|
|
+ global_process2lock::unlock($lockFile);
|
|
|
+ eeglobal_log_handler($logCatalog, "debug", "unlockafter lockCatalog=$lockCatalog lockId=$lockId");
|
|
|
+ }
|
|
|
+}
|
|
|
+function basecfg_getKey($subSystem, $groupKey)
|
|
|
+{
|
|
|
+ if (empty($groupKey)) {
|
|
|
+ throw new GeneralException("", "groupKey不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (empty(trim($subSystem))) {
|
|
|
+ $subSystem = "GC";
|
|
|
+ }
|
|
|
+
|
|
|
+ $groupKeyALL = trim($subSystem . "_" . $groupKey);
|
|
|
+ if (empty($groupKeyALL)) {
|
|
|
+ throw new GeneralException("", "groupKeyALL不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ $groupKeyCache = "GGCONFIG_$groupKeyALL";
|
|
|
+ return array(
|
|
|
+ "groupKeyALL" => $groupKeyALL,
|
|
|
+ "groupKeyCache" => $groupKeyCache,
|
|
|
+ );
|
|
|
+}
|
|
|
+function basecfg_getConfig($subSystem, $groupKey)
|
|
|
+{
|
|
|
+ $keyInfo = basecfg_getKey($subSystem, $groupKey);
|
|
|
+ $groupKeyALL = $keyInfo["groupKeyALL"];
|
|
|
+ $groupKeyCache = $keyInfo["groupKeyCache"];
|
|
|
+ if (!empty($GLOBALS[$groupKeyCache])) {
|
|
|
+ return $GLOBALS[$groupKeyCache];
|
|
|
+ }
|
|
|
+ $system_config_cache = pdo_fetch("select * from base_config where `group`=:group and `name`='system_config_cache'", array(':group' => $groupKeyALL));
|
|
|
+ if (empty($system_config_cache['value'])) {
|
|
|
+ $config = array();
|
|
|
+ $configdata = pdo_fetchall("select * from base_config where `group`=:group", array(':group' => $groupKeyALL));
|
|
|
+ foreach ($configdata as $item) {
|
|
|
+ $cvalue = $item['value'];
|
|
|
+ if (mb_strpos($item['value'], "YPWYPWARRAY") !== false) {
|
|
|
+ $cvalue = mb_ereg_replace("YPWYPWARRAY", "", $item['value']);
|
|
|
+ $cvalue = json_decode($cvalue, true);
|
|
|
+ }
|
|
|
+ $config[$item['name']] = $cvalue;
|
|
|
+ }
|
|
|
+ if (!empty($system_config_cache['name'])) {
|
|
|
+ pdo_update('base_config', array('value' => serialize($config)), array('name' => 'system_config_cache', 'group' => $groupKeyALL));
|
|
|
+ } else {
|
|
|
+ pdo_insert('base_config', array('name' => 'system_config_cache', 'value' => serialize($config), 'group' => $groupKeyALL));
|
|
|
+ }
|
|
|
+ $GLOBALS[$groupKeyCache] = $config;
|
|
|
+ return $GLOBALS[$groupKeyCache];
|
|
|
+ } else {
|
|
|
+ $GLOBALS[$groupKeyCache] = unserialize($system_config_cache['value']);
|
|
|
+ return $GLOBALS[$groupKeyCache];
|
|
|
+ }
|
|
|
+}
|
|
|
+function basecfg_setConfig($subSystem, $groupKey, $arrays, $needClear = false)
|
|
|
+{
|
|
|
+ $keyInfo = basecfg_getKey($subSystem, $groupKey);
|
|
|
+ $groupKeyALL = $keyInfo["groupKeyALL"];
|
|
|
+ $groupKeyCache = $keyInfo["groupKeyCache"];
|
|
|
+ if (empty($arrays) || !is_array($arrays) || count($arrays) <= 0) {
|
|
|
+ throw new GeneralException("", "basecfg_setConfig的参数arrays不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ $sqlTemp = "";
|
|
|
+ $sqlParam = array();
|
|
|
+ $sqlParam[":group"] = $groupKeyALL;
|
|
|
+ if ($needClear == true) {
|
|
|
+ $sqlTemp .= " delete from base_config where `group`=:group; ";
|
|
|
+ }
|
|
|
+
|
|
|
+ $index = 0;
|
|
|
+ foreach ($arrays as $cname => $cvalue) {
|
|
|
+ $index++;
|
|
|
+ $cnamePN = ":P{$index}_cname";
|
|
|
+ $cvaluePN = ":P{$index}_cvalue";
|
|
|
+ $sqlParam[$cnamePN] = $cname;
|
|
|
+ $sqlParam[$cvaluePN] = (!is_array($cvalue) ? $cvalue : "YPWYPWARRAY" . json_encode($cvalue));
|
|
|
+ $sqlTemp .= " set @handle_id='0'; "; //根据条件查询是否存在对应记录limit 1
|
|
|
+ $sqlTemp .= " select @handle_id:=`name` from base_config where `group`=:group and `name`=$cnamePN limit 1;";
|
|
|
+ //基于查询结果作为条件的dual虚表进行关联插入
|
|
|
+ $sqlTemp .= " insert into base_config ( `group`,`name`,`value` )";
|
|
|
+ $sqlTemp .= " select :group,$cnamePN,$cvaluePN from dual where ifnull(@handle_id,'0')='0' ;";
|
|
|
+ //候补更新,可能为空更新
|
|
|
+ $sqlTemp .= " update base_config SET `value`=$cvaluePN where ifnull(@handle_id,'0')<>'0' and `group`=:group and `name`=$cnamePN;";
|
|
|
+ }
|
|
|
+ $sqlTemp .= " update base_config SET `value`='' where `group`=:group and `name`='system_config_cache'; ";
|
|
|
+ pdo_query3($sqlTemp, $sqlParam);
|
|
|
+ unset($GLOBALS[$groupKeyCache]); //清理同一进程内可共享缓存
|
|
|
+}
|
|
|
+
|
|
|
+/**序列化相关**/
|
|
|
+function base_iserializer($value)
|
|
|
+{
|
|
|
+ return serialize($value);
|
|
|
+}
|
|
|
+function base_iunserializer($value)
|
|
|
+{
|
|
|
+ if (empty($value)) {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ if (!base_isserialized($value)) {
|
|
|
+ return $value;
|
|
|
+ }
|
|
|
+ $result = unserialize($value);
|
|
|
+ if ($result === false) {
|
|
|
+ $temp = preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $value);
|
|
|
+ return unserialize($temp);
|
|
|
+ }
|
|
|
+ return $result;
|
|
|
+}
|
|
|
+function base_isserialized($data, $strict = true)
|
|
|
+{
|
|
|
+ if (!is_string($data)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $data = trim($data);
|
|
|
+ if ('N;' == $data) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (strlen($data) < 4) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (':' !== $data[1]) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if ($strict) {
|
|
|
+ $lastc = substr($data, -1);
|
|
|
+ if (';' !== $lastc && '}' !== $lastc) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $semicolon = strpos($data, ';');
|
|
|
+ $brace = strpos($data, '}');
|
|
|
+ if (false === $semicolon && false === $brace) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (false !== $semicolon && $semicolon < 3) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (false !== $brace && $brace < 4) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ $token = $data[0];
|
|
|
+ switch ($token) {
|
|
|
+ case 's':
|
|
|
+ if ($strict) {
|
|
|
+ if ('"' !== substr($data, -2, 1)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ } elseif (false === strpos($data, '"')) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ case 'a':
|
|
|
+ case 'O':
|
|
|
+ return (bool) preg_match("/^{$token}:[0-9]+:/s", $data);
|
|
|
+ case 'b':
|
|
|
+ case 'i':
|
|
|
+ case 'd':
|
|
|
+ $end = $strict ? '$' : '';
|
|
|
+ return (bool) preg_match("/^{$token}:[0-9.E-]+;$end/", $data);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+function imghandle_buildAllUrl($oldUrl)
|
|
|
+{
|
|
|
+ if (empty($oldUrl)) {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+
|
|
|
+ $newUrl = $oldUrl;
|
|
|
+ if (mb_strpos(strtolower($oldUrl), "http") !== 0) {
|
|
|
+ $newUrl = WEBSITE_ROOT . $oldUrl;
|
|
|
+ }
|
|
|
+ return $newUrl;
|
|
|
+}
|
|
|
+function imghandle_createImage($imgurl)
|
|
|
+{
|
|
|
+ $resp = http_get(imghandle_buildAllUrl($imgurl));
|
|
|
+ return imagecreatefromstring($resp);
|
|
|
+}
|
|
|
+function imghandle_mergeImage($target, $data, $imgurl)
|
|
|
+{
|
|
|
+ $img = imghandle_createImage($imgurl);
|
|
|
+ $w = imagesx($img);
|
|
|
+ $h = imagesy($img);
|
|
|
+ if (intval($data['width']) <= 0) {
|
|
|
+ $data['width'] = $w;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (intval($data['height']) <= 0) {
|
|
|
+ $data['height'] = $w;
|
|
|
+ }
|
|
|
+
|
|
|
+ imagecopyresized($target, $img, $data['left'], $data['top'], 0, 0, $data['width'], $data['height'], $w, $h);
|
|
|
+ imagedestroy($img);
|
|
|
+ return $target;
|
|
|
+}
|
|
|
+function imghandle_mergeText($target, $data, $text, $fontFileName)
|
|
|
+{
|
|
|
+ $font = WEB_PHY_ASSETROOT . "/font/$fontFileName.ttf";
|
|
|
+ if (!file_exists($font)) {
|
|
|
+ $font = WEB_PHY_ASSETROOT . "/font/msyh.ttf";
|
|
|
+ }
|
|
|
+ if (intval($data['size']) <= 0) {
|
|
|
+ $data['size'] = 12;
|
|
|
+ }
|
|
|
+
|
|
|
+ $colors = imghandle_hex2rgb($data['color']);
|
|
|
+ if (empty($colors)) {
|
|
|
+ $colors = array('red' => 0, 'green' => 0, 'blue' => 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ $color = imagecolorallocate($target, $colors['red'], $colors['green'], $colors['blue']);
|
|
|
+ if (intval($data['width']) <= 0) {
|
|
|
+ $data['width'] = 50;
|
|
|
+ }
|
|
|
+
|
|
|
+ mb_internal_encoding("UTF-8"); //设置编码
|
|
|
+ $content = "";
|
|
|
+ // 将字符串拆分成一个个单字 保存到数组 letter 中
|
|
|
+ for ($i = 0; $i < mb_strlen($text); $i++) {
|
|
|
+ $letter[] = mb_substr($text, $i, 1);
|
|
|
+ }
|
|
|
+ foreach ($letter as $l) {
|
|
|
+ $teststr = $content . " " . $l;
|
|
|
+ $fontBox = imagettfbbox($data['size'], 0, $font, $teststr);
|
|
|
+ // 判断拼接后的字符串是否超过预设的宽度
|
|
|
+ if (($fontBox[2] > intval($data['width'])) && ($content !== "")) {
|
|
|
+ $content .= "\n";
|
|
|
+ }
|
|
|
+ $content .= $l;
|
|
|
+ }
|
|
|
+ imagettftext($target, $data['size'], 0, $data['left'], $data['top'] + $data['size'], $color, $font, $content);
|
|
|
+ return $target;
|
|
|
+}
|
|
|
+function imghandle_hex2rgb($colour)
|
|
|
+{
|
|
|
+ if ($colour[0] == '#') {
|
|
|
+ $colour = substr($colour, 1);
|
|
|
+ }
|
|
|
+ if (strlen($colour) == 6) {
|
|
|
+ list($r, $g, $b) = array(
|
|
|
+ $colour[0] . $colour[1],
|
|
|
+ $colour[2] . $colour[3],
|
|
|
+ $colour[4] . $colour[5],
|
|
|
+ );
|
|
|
+ } elseif (strlen($colour) == 3) {
|
|
|
+ list($r, $g, $b) = array(
|
|
|
+ $colour[0] . $colour[0],
|
|
|
+ $colour[1] . $colour[1],
|
|
|
+ $colour[2] . $colour[2],
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $r = hexdec($r);
|
|
|
+ $g = hexdec($g);
|
|
|
+ $b = hexdec($b);
|
|
|
+ return array(
|
|
|
+ 'red' => $r,
|
|
|
+ 'green' => $g,
|
|
|
+ 'blue' => $b,
|
|
|
+ );
|
|
|
+}
|
|
|
+function poster_build_pre($bizCatalog, $bizid, $userid, $poster, $saveSubPath, $cbQR, $cbQrMina)
|
|
|
+{
|
|
|
+ $bizCatalog = intval($bizCatalog);
|
|
|
+ $bizid = intval($bizid);
|
|
|
+ $userid = intval($userid);
|
|
|
+ foreach ($poster["data"] as &$d) {
|
|
|
+ if ($d['type'] == 'qr') {
|
|
|
+ $qr_imgtype = $d["imgtype"] == "png" ? "png" : "jpeg";
|
|
|
+ $qr_md5 = md5(json_encode($d));
|
|
|
+ $qr_fileName = "{$bizCatalog}_{$bizid}_{$userid}_$qr_md5.{$qr_imgtype}";
|
|
|
+ $bizData = $cbQR($bizCatalog, $bizid, $userid, $d);
|
|
|
+ $qrEmbedData = $bizData["qrEmbedData"];
|
|
|
+ $qrSubPath = $bizData["qrSubPath"];
|
|
|
+ $qr_pathPath = "$qrSubPath/$qr_fileName";
|
|
|
+ $qr_urlPath = WEB_URL_FILEROOT . "/$qr_pathPath";
|
|
|
+ $qr_phyPath = WEB_PHY_FILEROOT . "/$qr_pathPath";
|
|
|
+ $destPhyPath = dirname($qr_phyPath);
|
|
|
+ if (!is_dir($destPhyPath)) {
|
|
|
+ oshandle_mkdirs($destPhyPath);
|
|
|
+ }
|
|
|
+ if (!file_exists($qr_phyPath)) {
|
|
|
+ require_once WEB_PHY_ROOT . "/base/lib_qr.php";
|
|
|
+ $d['margin'] = intval(str_replace('px', '', $d['margin']));
|
|
|
+ $d['size'] = intval(str_replace('px', '', $d['size']));
|
|
|
+ lib_qrbuild_core($qr_imgtype, $qrEmbedData, $qr_phyPath, $d['size'], $d['margin']
|
|
|
+ , null, null, null, null, $d["logpath"]);
|
|
|
+ }
|
|
|
+ $d['src'] = $qr_urlPath;
|
|
|
+ $d['type'] = "img";
|
|
|
+ } else if ($d['type'] == 'qrmina') {
|
|
|
+ $qrmina_imgtype = $d["imgtype"] == "png" ? "png" : "jpeg";
|
|
|
+ $qrmina_md5 = md5(json_encode($d));
|
|
|
+ $qrmina_fileName = "{$bizCatalog}_{$bizid}_{$userid}_$qrmina_md5.{$qrmina_imgtype}";
|
|
|
+ $bizData = $cbQrMina($bizCatalog, $bizid, $userid, $d);
|
|
|
+ $qrminaSubPath = $bizData["qrminaSubPath"];
|
|
|
+ $qrminaAppId = $bizData["qrminaAppId"];
|
|
|
+ $qrminaAppSecret = $bizData["qrminaAppSecret"];
|
|
|
+ $qrminaPagePath = $bizData["qrminaPagePath"];
|
|
|
+ $qrmina_pathPath = "$qrminaSubPath/$qrmina_fileName";
|
|
|
+ $qrmina_urlPath = WEB_URL_FILEROOT . "/$qrmina_pathPath";
|
|
|
+ $qrmina_phyPath = WEB_PHY_FILEROOT . "/$qrmina_pathPath";
|
|
|
+ $destPhyPath = dirname($qrmina_phyPath);
|
|
|
+ if (!is_dir($destPhyPath)) {
|
|
|
+ oshandle_mkdirs($destPhyPath);
|
|
|
+ }
|
|
|
+ if (!file_exists($qrmina_phyPath)) {
|
|
|
+ require_once WEB_PHY_ROOT . "/base/wxsrv.php";
|
|
|
+ $d['size'] = intval(str_replace('px', '', $d['size']));
|
|
|
+ weixin_getMinaQCode($qrminaAppId, $qrminaAppSecret, $qrmina_phyPath,
|
|
|
+ $bizCatalog, $bizid, $userid, $qrminaPagePath, $d['size']);
|
|
|
+ }
|
|
|
+ $d['src'] = $qrmina_urlPath;
|
|
|
+ $d['type'] = "img";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $poster_md5 = md5(json_encode(array(
|
|
|
+ 'version' => 1,
|
|
|
+ 'catalog' => $bizCatalog,
|
|
|
+ 'bizid' => $bizid,
|
|
|
+ 'userid' => $userid,
|
|
|
+ 'width' => $poster["width"],
|
|
|
+ 'height' => $poster["height"],
|
|
|
+ 'bg' => $poster["bg"],
|
|
|
+ 'data' => $poster["data"],
|
|
|
+ 'imgtype' => $poster["imgtype"],
|
|
|
+ )));
|
|
|
+ $poster_fileName = "{$bizCatalog}_{$bizid}_{$userid}_$poster_md5.{$poster["imgtype"]}";
|
|
|
+ $poster_pathPath = "$saveSubPath/$poster_fileName";
|
|
|
+ $poster_phyPath = WEB_PHY_FILEROOT . "/$poster_pathPath";
|
|
|
+ $destPhyPath = dirname($poster_phyPath);
|
|
|
+ if (!is_dir($destPhyPath)) {
|
|
|
+ oshandle_mkdirs($destPhyPath);
|
|
|
+ }
|
|
|
+ if (!file_exists($poster_phyPath)) {
|
|
|
+ poster_build($poster["width"], $poster["height"], $poster["bg"], $poster["data"], $poster_phyPath, $poster["imgtype"]);
|
|
|
+ }
|
|
|
+ return WEB_URL_FILEROOT . "/$poster_pathPath";
|
|
|
+}
|
|
|
+function poster_build($width, $height, $bgPicPath, $data, $savePath, $saveType = "jpg")
|
|
|
+{
|
|
|
+ set_time_limit(0);
|
|
|
+ @ini_set('memory_limit', '256M');
|
|
|
+ $width = intval($width);
|
|
|
+ if ($width < 10) {
|
|
|
+ $width = 10;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($width > 1240) {
|
|
|
+ $width = 1240;
|
|
|
+ }
|
|
|
+
|
|
|
+ $height = intval($height);
|
|
|
+ if ($height < 10) {
|
|
|
+ $height = 10;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($height > 1624) {
|
|
|
+ $height = 1624;
|
|
|
+ }
|
|
|
+
|
|
|
+ $target = imagecreatetruecolor($width, $height);
|
|
|
+ if (!empty($bgPicPath)) {
|
|
|
+ $bg = imghandle_createImage($bgPicPath);
|
|
|
+ imagecopy($target, $bg, 0, 0, 0, 0, $width, $height);
|
|
|
+ imagedestroy($bg);
|
|
|
+ }
|
|
|
+ foreach ($data as $d) {
|
|
|
+ $d['left'] = intval(str_replace('px', '', $d['left']));
|
|
|
+ $d['top'] = intval(str_replace('px', '', $d['top']));
|
|
|
+ $d['width'] = intval(str_replace('px', '', $d['width']));
|
|
|
+ $d['height'] = intval(str_replace('px', '', $d['height']));
|
|
|
+ $d['size'] = intval(str_replace('px', '', $d['size']));
|
|
|
+ $d['src'] = imghandle_buildAllUrl($d['src']);
|
|
|
+ if ($d['type'] == 'img') {
|
|
|
+ $target = imghandle_mergeImage($target, $d, $d['src']);
|
|
|
+ } else if ($d['type'] == 'text') {
|
|
|
+ if ($d['width'] <= 0) {
|
|
|
+ $d['width'] = $width;
|
|
|
+ }
|
|
|
+
|
|
|
+ $target = imghandle_mergeText($target, $d, $d['text'], $d['font']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $saveType == "jpg" ? imagejpeg($target, $savePath) : imagepng($target, $savePath);
|
|
|
+ imagedestroy($target);
|
|
|
+}
|
|
|
+
|
|
|
+function base_putForendErrLog($forendtype)
|
|
|
+{
|
|
|
+ $GPC = input_param_handle(false);
|
|
|
+ $ajaxdata = input_getPostObj();
|
|
|
+ $forendid = isset($ajaxdata["forendid"]) ? $ajaxdata["forendid"] : $GPC["forendid"];
|
|
|
+ if (empty(trim($forendid))) {
|
|
|
+ $forendid = "无";
|
|
|
+ }
|
|
|
+
|
|
|
+ $catalog = isset($ajaxdata["catalog"]) ? $ajaxdata["catalog"] : $GPC["catalog"];
|
|
|
+ if (empty(trim($catalog))) {
|
|
|
+ $catalog = "无";
|
|
|
+ }
|
|
|
+
|
|
|
+ $content = isset($ajaxdata["content"]) ? $ajaxdata["content"] : $GPC["content"];
|
|
|
+ if (empty(trim($content))) {
|
|
|
+ $content = "没有传递content,内容为空";
|
|
|
+ }
|
|
|
+
|
|
|
+ pdo_insert("base_forend_errlog", array(
|
|
|
+ "createtime" => time(),
|
|
|
+ "forendtype" => $forendtype,
|
|
|
+ "forendid" => $forendid,
|
|
|
+ "errcatalog" => $catalog,
|
|
|
+ "errcontent" => $content,
|
|
|
+ ));
|
|
|
+}
|
|
|
+function base_buildForendToken($userInfo)
|
|
|
+{
|
|
|
+ $stoptime = time() + 3600 * 24 * 15;
|
|
|
+ $userInfo["salt"] = random(8);
|
|
|
+ pdo_query("update base_user set salt=:salt where id=:id;", array(
|
|
|
+ ":salt" => $userInfo["salt"], ":id" => $userInfo["id"],
|
|
|
+ ));
|
|
|
+ switch (FOREND_TOKEN_MODE) {
|
|
|
+ default:
|
|
|
+ $nowsign = base_getforendTokenSign($userInfo, $stoptime);
|
|
|
+ return FOREND_TOKEN_MODE . "_$stoptime$nowsign";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+}
|
|
|
+function base_getforendTokenSign($userInfo, $stoptime)
|
|
|
+{
|
|
|
+ return md5(trim($stoptime) . "_" . trim($userInfo["id"]) . "_" . trim($userInfo["createtime"]) . "_" . trim($userInfo["salt"]));
|
|
|
+}
|
|
|
+function base_verifyForendToken($userInfo)
|
|
|
+{
|
|
|
+ $GPC = input_param_handle(false);
|
|
|
+ $ajaxdata = input_getPostObj();
|
|
|
+ $token = isset($ajaxdata[FOREND_TOKEN_NAME]) ? $ajaxdata[FOREND_TOKEN_NAME] : $GPC[FOREND_TOKEN_NAME];
|
|
|
+ if (empty(trim($token))) {
|
|
|
+ throw new GeneralException("", "没有传递前端会话Token的参数[ " . FOREND_TOKEN_NAME . " ]或参数为空!");
|
|
|
+ }
|
|
|
+
|
|
|
+ $token = mb_ereg_replace("_", "", $token);
|
|
|
+ switch (intval($token[0])) { //0-md5/sha1; 1-对称加密; 2-非对称加密
|
|
|
+ default:
|
|
|
+ $stoptime = mb_substr($token, 1, 10);
|
|
|
+ if (time() > intval($stoptime)) {
|
|
|
+ base_verifyForendTokenFail("会话令牌已过期,请重新登录验证以获取新令牌!");
|
|
|
+ }
|
|
|
+
|
|
|
+ $oldsign = mb_substr($token, 11);
|
|
|
+ $nowsign = base_getforendTokenSign($userInfo, $stoptime);
|
|
|
+ if ($oldsign != $nowsign) {
|
|
|
+ base_verifyForendTokenFail("会话令牌不匹配,请重新登录验证以获取新令牌!");
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+}
|
|
|
+function base_verifyForendTokenFail($attachMsg = "会话令牌无效,请重新登录验证以获取新令牌!")
|
|
|
+{
|
|
|
+ $ajaxRes = new AjaxResult;
|
|
|
+ $ajaxRes->ErrMsg = FOREND_TOKEN_ERRMSGFLAG . $attachMsg;
|
|
|
+ ob_clean();
|
|
|
+ ob_start();
|
|
|
+ header('Content-Type:application/json;charset=UTF-8');
|
|
|
+ echo @json_encode($ajaxRes);
|
|
|
+ exit;
|
|
|
+}
|
|
|
+
|
|
|
+function base_loginByPhone($subSystem)
|
|
|
+{
|
|
|
+ $GPC = input_param_handle(false);
|
|
|
+ $ajaxdata = input_getPostObj();
|
|
|
+ $phone = isset($ajaxdata["phone"]) ? $ajaxdata["phone"] : $GPC["phone"];
|
|
|
+ if (empty($phone)) {
|
|
|
+ throw new GeneralException("", "没有传递必要的phone参数");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!preg_match("/^1\d{10,10}$/", trim($phone))) {
|
|
|
+ throw new GeneralException("", "传递的不是正确的手机号");
|
|
|
+ }
|
|
|
+ $code = isset($ajaxdata["code"]) ? $ajaxdata["code"] : $GPC["code"];
|
|
|
+ if ($phone == "18920787806" && (intval($subSystem) == 1)) {
|
|
|
+ $code = "123456";
|
|
|
+ }
|
|
|
+//会员侧测试锁码,用于测试及第三方验证
|
|
|
+ if ($phone == "13920062668" && (intval($subSystem) == 2)) {
|
|
|
+ $code = "687206";
|
|
|
+ }
|
|
|
+//商家侧测试锁码,用于测试及第三方验证
|
|
|
+ if (empty(trim($code))) {
|
|
|
+ $code = rand(123456, 654321);
|
|
|
+ /***UPSERT手机用户记录**start***/
|
|
|
+ $sqlTemp = "";
|
|
|
+ $sqlParam = array();
|
|
|
+ $sqlParam[":nowtime"] = time();
|
|
|
+ $sqlParam[":subsystem"] = intval($subSystem);
|
|
|
+ $sqlParam[":mobile"] = trim($phone);
|
|
|
+ $sqlParam[":smscode"] = $code;
|
|
|
+ $sqlParam[":salt"] = random(8);
|
|
|
+ $sqlTemp .= " set @handle_id='0'; ";
|
|
|
+ $sqlTemp .= " select @handle_id:=`mobile` from base_user where subsystem=:subsystem and `mobile`=:mobile limit 1;";
|
|
|
+ $sqlTemp .= " insert into base_user ( `createtime`,`subsystem`,`mobile`,`smscode`,`salt` )";
|
|
|
+ $sqlTemp .= " select :nowtime ,:subsystem ,:mobile ,:smscode ,:salt from dual where ifnull(@handle_id,'0')='0' ;";
|
|
|
+ $sqlTemp .= " update base_user SET `updatetime`=:nowtime,`smscode`=:smscode where ifnull(@handle_id,'0')<>'0' and subsystem=:subsystem and `mobile`=:mobile;";
|
|
|
+ pdo_query3($sqlTemp, $sqlParam);
|
|
|
+ /***UPSERT手机用户记录**finish***/
|
|
|
+ include_once WEB_PHY_ROOT . "/base/smslib.php"; //发短信阿里
|
|
|
+ $sended = alisms_sendSms($phone, AliSMS_CODE_TMPCODE, AliSMS_CODE_TMPSIGN, array("code" => $code));
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ $baseUser = pdo_fetch("select * from base_user where subsystem=:subsystem and `mobile`=:mobile limit 1;", array(
|
|
|
+ ":subsystem" => intval($subSystem),
|
|
|
+ ":mobile" => trim($phone),
|
|
|
+ ));
|
|
|
+ if (empty($baseUser)) {
|
|
|
+ throw new GeneralException("", "没有定位到此手机号的用户记录,请先不带code参数方式调用此接口先获取验证码并预构建手机用户记录!");
|
|
|
+ }
|
|
|
+ if (trim($baseUser["smscode"]) != trim($code)) {
|
|
|
+ throw new GeneralException("", "输入的短信验证码不正确,或者已过期!");
|
|
|
+ } else { //生成并返给前端会话token
|
|
|
+ $baseUser["FOREND_TOKEN"] = base_buildForendToken($baseUser);
|
|
|
+ return $baseUser;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+function basebaidumap_fetchplace($lat, $lng, $coordtype = "wgs84ll")
|
|
|
+{
|
|
|
+ $url = "https://api.map.baidu.com/reverse_geocoding/v3/?";
|
|
|
+ $url .= "ak=" . BaiduLBS_APPKEY;
|
|
|
+ $url .= "&output=json&coordtype={$coordtype}";
|
|
|
+ $url .= "&location={$lat},{$lng}";
|
|
|
+ $result = http_get($url);
|
|
|
+ $obj = @json_decode($result, true);
|
|
|
+ if (!empty($obj) && intval($obj["status"]) == 0
|
|
|
+ && is_array($obj["result"]) && !empty($obj["result"]["formatted_address"])) {
|
|
|
+ return $obj["result"];
|
|
|
+ } else {
|
|
|
+ throw new Exception($result);
|
|
|
+ }
|
|
|
+}
|
|
|
+//-----------------------------------------------------
|
|
|
+use AlibabaCloud\SDK\Dyplsapi\V20170525\Dyplsapi;
|
|
|
+use Darabonba\OpenApi\Models\Config;
|
|
|
+use AlibabaCloud\SDK\Dyplsapi\V20170525\Models\CreateSubscriptionRequest;
|
|
|
+use AlibabaCloud\SDK\Dyplsapi\V20170525\Models\BindAxnRequest;
|
|
|
+function alivphone_BindAxn($expiration, $phoneNoA, $poolKey)
|
|
|
+{
|
|
|
+ require_once WEB_PHY_ROOT . "/base/composer/vendor/autoload.php";
|
|
|
+ try {
|
|
|
+ $config = new Config([
|
|
|
+ "accessKeyId" => AliSMSAccessKey,
|
|
|
+ "accessKeySecret" => AliSMSAccessSecret,
|
|
|
+ ]);
|
|
|
+ $config->endpoint = "dyplsapi.aliyuncs.com";
|
|
|
+ $client = new Dyplsapi($config);
|
|
|
+ $bindAxnRequest = new BindAxnRequest([
|
|
|
+ "poolKey" => $poolKey,
|
|
|
+ "phoneNoA" => $phoneNoA,
|
|
|
+ "expiration" => date("Y-m-d H:i:s", $expiration),
|
|
|
+ ]);
|
|
|
+ eeglobal_log_handler('alivphone_BindAxn', 'info', "bindAxnRequest=>" . json_encode($bindAxnRequest));
|
|
|
+ $response = $client->bindAxn($bindAxnRequest);
|
|
|
+ if ($response->body->code == "OK") {
|
|
|
+ eeglobal_log_handler('alivphone_BindAxn', 'info', "bindok=>" . json_encode($response->body->secretBindDTO));
|
|
|
+ $secretNo = $response->body->secretBindDTO->secretNo;
|
|
|
+ $subsId = $response->body->secretBindDTO->subsId;
|
|
|
+ return array("secretNo" => $secretNo, "subsId" => $subsId);
|
|
|
+ } else {
|
|
|
+ throw new GeneralException("AlibabaCloudError", json_encode($response->body));
|
|
|
+ }
|
|
|
+ } catch (Throwable $ex) {
|
|
|
+ throw new GeneralException("AlibabaCloudError", $ex->getMessage());
|
|
|
+ }
|
|
|
+}
|
|
|
+use AlibabaCloud\SDK\Dyplsapi\V20170525\Models\QueryCallStatusRequest;
|
|
|
+function alivphone_QueryCallStatus($poolKey, $subsId)
|
|
|
+{
|
|
|
+ require_once WEB_PHY_ROOT . "/base/composer/vendor/autoload.php";
|
|
|
+ try {
|
|
|
+ $config = new Config([
|
|
|
+ "accessKeyId" => AliSMSAccessKey,
|
|
|
+ "accessKeySecret" => AliSMSAccessSecret,
|
|
|
+ ]);
|
|
|
+ $config->endpoint = "dyplsapi.aliyuncs.com";
|
|
|
+ $client = new Dyplsapi($config);
|
|
|
+ $queryCallStatusRequest = new QueryCallStatusRequest([
|
|
|
+ "poolKey" => $poolKey,
|
|
|
+ "subsId" => $subsId,
|
|
|
+ ]);
|
|
|
+ eeglobal_log_handler('alivphone_QueryCallStatus', 'info', "queryCallStatusRequest=>" . json_encode($queryCallStatusRequest));
|
|
|
+ $response = $client->queryCallStatus($queryCallStatusRequest);
|
|
|
+ if ($response->body->code == "OK") {
|
|
|
+ eeglobal_log_handler('alivphone_QueryCallStatus', 'info', "queryok=>" . json_encode($response->body->secretCallStatusDTO));
|
|
|
+ $calledNo = $response->body->secretCallStatusDTO->calledNo;
|
|
|
+ $status = $response->body->secretCallStatusDTO->status;
|
|
|
+ return array("calledNo" => $calledNo, "status" => $status);
|
|
|
+ } else {
|
|
|
+ throw new GeneralException("AlibabaCloudError", json_encode($response->body));
|
|
|
+ }
|
|
|
+ } catch (Throwable $ex) {
|
|
|
+ throw new GeneralException("AlibabaCloudError", $ex->getMessage());
|
|
|
+ }
|
|
|
+}
|
|
|
+/**************************************************************/
|
|
|
+function baseexcel_exportCsv($fileName, $title, $args, $handle)
|
|
|
+{
|
|
|
+ require_once WEB_PHY_ROOT . "/base/composer/vendor/autoload.php";
|
|
|
+ set_time_limit(0);
|
|
|
+ $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
|
|
+ $activeSheet = $spreadsheet->getActiveSheet();
|
|
|
+ foreach ($title as $key => $value) {
|
|
|
+ $activeSheet->setCellValueByColumnAndRow($key + 1, 1, $value);
|
|
|
+ }
|
|
|
+ $writer = new \PhpOffice\PhpSpreadsheet\Writer\Csv($spreadsheet);
|
|
|
+ $writer->setOutputEncoding("GBK");
|
|
|
+ $writer->save('php://output');
|
|
|
+ $fp = fopen('php://output', 'w'); //打开output流
|
|
|
+ header("Content-Description: File Transfer");
|
|
|
+ header("Expires: 0");
|
|
|
+ header("Cache-Control: must-revalidate");
|
|
|
+ header("Pragma: public");
|
|
|
+ header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
+ header("Content-Disposition: attachment;filename={$fileName}.csv");
|
|
|
+ header("Cache-Control: max-age=0");
|
|
|
+ do {
|
|
|
+ $backdata = $handle($args);
|
|
|
+ if (empty($backdata)) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ $pagedata = $backdata["pagedata"];
|
|
|
+ if (empty($pagedata)) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ $args = $backdata["args"];
|
|
|
+ foreach ($pagedata as $item) {
|
|
|
+ mb_convert_variables('GBK', 'UTF-8', $item);
|
|
|
+ fputcsv($fp, $item);
|
|
|
+ }
|
|
|
+ ob_flush();
|
|
|
+ flush();
|
|
|
+ } while (!empty($pagedata));
|
|
|
+ fclose($fp);
|
|
|
+ exit();
|
|
|
+}
|
|
|
+
|
|
|
+function base_buildSNById($prefix, $id, $prefixMaxLen = 11, $zeroPadMaxLen = 11)
|
|
|
+{
|
|
|
+ $strId = intval($id) . "";
|
|
|
+ if ((intval($prefixMaxLen) - mb_strlen($strId)) <= 0) {
|
|
|
+ $prefix = "";
|
|
|
+ }
|
|
|
+
|
|
|
+ $diff = intval($zeroPadMaxLen) - mb_strlen($strId);
|
|
|
+ $strPad = "";
|
|
|
+ for ($iii = 0; $diff > 0 && $iii < $diff; $iii++) {
|
|
|
+ $strPad .= "0";
|
|
|
+ }
|
|
|
+
|
|
|
+ return $prefix . $strPad . $strId;
|
|
|
+}
|
|
|
+function base_fetchIdBySN($sn)
|
|
|
+{
|
|
|
+ preg_match_all('/\d/', $sn, $arr);
|
|
|
+ $id = implode($arr[0]);
|
|
|
+ return intval($id);
|
|
|
+}
|