|
@@ -3,327 +3,346 @@
|
|
|
use think\facade\Env;
|
|
|
use think\facade\Db;
|
|
|
use Aliyun\OTS\OTSClient;
|
|
|
- /**
|
|
|
- * 增量解析含wifi信号Gps
|
|
|
- */
|
|
|
- function queryTableStoreGpsRoute($options){
|
|
|
-
|
|
|
- if(!isset($options['device_number']) && $options['device_number'] !=''){
|
|
|
- return array('success'=>false,'message'=>'缺少设备号');
|
|
|
- }
|
|
|
- $device_number=$options['device_number'];
|
|
|
- if(!isset($options['start_time']) && $options['start_time']>0){
|
|
|
- return array('success'=>false,'message'=>'缺少起始时间');
|
|
|
- }
|
|
|
- $start_time=$options['start_time'];
|
|
|
- if(!isset($options['end_time']) && $options['end_time']>0){
|
|
|
- $end_time=time();
|
|
|
- }else{
|
|
|
- $end_time=$options['end_time'];
|
|
|
- }
|
|
|
-
|
|
|
- if(!isset($options['table_name']) && $options['table_name']>0){
|
|
|
- return array('success'=>false,'message'=>'缺少表名参数');
|
|
|
- }
|
|
|
- $table_name=$options['table_name'];
|
|
|
-
|
|
|
-
|
|
|
- // $otsClient = new OTSClient (array (
|
|
|
- // 'EndPoint' => 'https://rlfd.cn-hangzhou.ots.aliyuncs.com',
|
|
|
- // 'AccessKeyID' => 'LTAI4FecTAyMPdhAdkUwhAGA',
|
|
|
- // 'AccessKeySecret' => 'Ih0knSSfcje3OUi1YrdjeXQZYIfmTK',
|
|
|
- // 'InstanceName' => 'rlfd',
|
|
|
- // ));
|
|
|
- $table_config=Db::table('sys_config')->where('type','table_store')->column('fieldValue','field');
|
|
|
- if(!isset($table_config['EndPoint']) || !isset($table_config['AccessKeyID']) || !isset($table_config['AccessKeySecret']) || !isset($table_config['InstanceName'])){
|
|
|
- return array('success'=>false,'message'=>'未配置表格存储');
|
|
|
- }
|
|
|
- $otsClient = new OTSClient (array (
|
|
|
- 'EndPoint' => $table_config['EndPoint'],
|
|
|
- 'AccessKeyID' => $table_config['AccessKeyID'],
|
|
|
- 'AccessKeySecret' => $table_config['AccessKeySecret'],
|
|
|
- 'InstanceName' => $table_config['InstanceName'],
|
|
|
- ));
|
|
|
- $otsClient->getClientConfig()->debugLogHandler = null;
|
|
|
- $otsClient->getClientConfig()->errorLogHandler = null;
|
|
|
- // var_dump($otsClient);
|
|
|
- ini_set('memory_limit', '512M');
|
|
|
-
|
|
|
- $startPK = array (
|
|
|
- array('DeviceNumber',$device_number),
|
|
|
- array('Timestamp', $start_time)
|
|
|
- // array('Timestamp', 1620885120)
|
|
|
- );
|
|
|
- $endPK = array (
|
|
|
- array('DeviceNumber', $device_number),
|
|
|
- array('Timestamp', $end_time)
|
|
|
- // array('Timestamp', 1620885441)
|
|
|
+
|
|
|
+/**
|
|
|
+ * 增量解析含wifi信号Gps
|
|
|
+ */
|
|
|
+function queryTableStoreGpsRoute($options)
|
|
|
+{
|
|
|
+
|
|
|
+ if (!isset($options['device_number']) && $options['device_number'] != '') {
|
|
|
+ return array('success' => false, 'message' => '缺少设备号');
|
|
|
+ }
|
|
|
+ $device_number = $options['device_number'];
|
|
|
+ if (!isset($options['start_time']) && $options['start_time'] > 0) {
|
|
|
+ return array('success' => false, 'message' => '缺少起始时间');
|
|
|
+ }
|
|
|
+ $start_time = $options['start_time'];
|
|
|
+ if (!isset($options['end_time']) && $options['end_time'] > 0) {
|
|
|
+ $end_time = time();
|
|
|
+ } else {
|
|
|
+ $end_time = $options['end_time'];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!isset($options['table_name']) && $options['table_name'] > 0) {
|
|
|
+ return array('success' => false, 'message' => '缺少表名参数');
|
|
|
+ }
|
|
|
+ $table_name = $options['table_name'];
|
|
|
+
|
|
|
+
|
|
|
+ // $otsClient = new OTSClient (array (
|
|
|
+ // 'EndPoint' => 'https://rlfd.cn-hangzhou.ots.aliyuncs.com',
|
|
|
+ // 'AccessKeyID' => 'LTAI4FecTAyMPdhAdkUwhAGA',
|
|
|
+ // 'AccessKeySecret' => 'Ih0knSSfcje3OUi1YrdjeXQZYIfmTK',
|
|
|
+ // 'InstanceName' => 'rlfd',
|
|
|
+ // ));
|
|
|
+ $table_config = Db::table('sys_config')->where('type', 'table_store')->column('fieldValue', 'field');
|
|
|
+ if (!isset($table_config['EndPoint']) || !isset($table_config['AccessKeyID']) || !isset($table_config['AccessKeySecret']) || !isset($table_config['InstanceName'])) {
|
|
|
+ return array('success' => false, 'message' => '未配置表格存储');
|
|
|
+ }
|
|
|
+ $otsClient = new OTSClient(array(
|
|
|
+ 'EndPoint' => $table_config['EndPoint'],
|
|
|
+ 'AccessKeyID' => $table_config['AccessKeyID'],
|
|
|
+ 'AccessKeySecret' => $table_config['AccessKeySecret'],
|
|
|
+ 'InstanceName' => $table_config['InstanceName'],
|
|
|
+ ));
|
|
|
+ $otsClient->getClientConfig()->debugLogHandler = null;
|
|
|
+ $otsClient->getClientConfig()->errorLogHandler = null;
|
|
|
+ // var_dump($otsClient);
|
|
|
+ ini_set('memory_limit', '512M');
|
|
|
+
|
|
|
+ $startPK = array(
|
|
|
+ array('DeviceNumber', $device_number),
|
|
|
+ array('Timestamp', $start_time)
|
|
|
+ // array('Timestamp', 1620885120)
|
|
|
+ );
|
|
|
+ $endPK = array(
|
|
|
+ array('DeviceNumber', $device_number),
|
|
|
+ array('Timestamp', $end_time)
|
|
|
+ // array('Timestamp', 1620885441)
|
|
|
+ );
|
|
|
+ if (isset($options['limit']) && $options['limit'] > 0) {
|
|
|
+ $limit = $options['limit'];
|
|
|
+ } else {
|
|
|
+ $limit = 5500;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $rows = [];
|
|
|
+ while (!empty($startPK) && $limit > 0) {
|
|
|
+
|
|
|
+ $request = array(
|
|
|
+ 'table_name' => $table_name,
|
|
|
+ 'max_versions' => 1,
|
|
|
+ 'direction' => 'BACKWARD', // 方向可以为 FORWARD 或者 BACKWARD
|
|
|
+ 'inclusive_start_primary_key' => $endPK, // 开始主键
|
|
|
+ 'exclusive_end_primary_key' => $startPK, // 结束主键
|
|
|
+ 'limit' => $limit
|
|
|
);
|
|
|
- if(isset($options['limit']) && $options['limit']>0){
|
|
|
- $limit = $options['limit'];
|
|
|
- }else{
|
|
|
- $limit = 5500;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- $rows=[];
|
|
|
- while (! empty ($startPK) && $limit > 0) {
|
|
|
-
|
|
|
- $request = array (
|
|
|
- 'table_name' => $table_name,
|
|
|
- 'max_versions' => 1,
|
|
|
- 'direction' => 'BACKWARD', // 方向可以为 FORWARD 或者 BACKWARD
|
|
|
- 'inclusive_start_primary_key' => $endPK, // 开始主键
|
|
|
- 'exclusive_end_primary_key' => $startPK, // 结束主键
|
|
|
- 'limit' => $limit
|
|
|
- );
|
|
|
-
|
|
|
-
|
|
|
- $response = [];
|
|
|
- try {
|
|
|
- $response = $otsClient->getRange($request);
|
|
|
- } catch (\Exception $e) {
|
|
|
- var_dump($e->getMessage());
|
|
|
- }
|
|
|
-
|
|
|
- if (!isset($response['rows'])){
|
|
|
- return CatchResponse::success([]);
|
|
|
- }
|
|
|
-
|
|
|
- foreach ($response['rows'] as $rowData) {
|
|
|
- // $str=($limit-4000)/2000;
|
|
|
- $item=[];
|
|
|
- foreach($rowData['primary_key'] as $keyItem){
|
|
|
- $item[$keyItem[0]]=$keyItem[1];
|
|
|
- }
|
|
|
- foreach($rowData['attribute_columns'] as $colItem){
|
|
|
- $item[$colItem[0]]=$colItem[1];
|
|
|
- }
|
|
|
- $item['PassTime']=date('Y-m-d H:i:s',$item['Timestamp']);
|
|
|
- $rows[]=$item;
|
|
|
- $limit --;
|
|
|
-
|
|
|
- // 处理每一行数据
|
|
|
- }
|
|
|
-
|
|
|
- $startPK = $response['next_start_primary_key'];
|
|
|
- // 如果 next_start_primary_key 不为空并且 limit > 0 则循环继续
|
|
|
- }
|
|
|
- if(!$rows){
|
|
|
- return array('success'=>true,'message'=>'查询成功','data'=>[]);
|
|
|
+
|
|
|
+
|
|
|
+ $response = [];
|
|
|
+ try {
|
|
|
+ $response = $otsClient->getRange($request);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ var_dump($e->getMessage());
|
|
|
}
|
|
|
|
|
|
- $arr= [];
|
|
|
-
|
|
|
- foreach($rows as $k=> $v){
|
|
|
- if( !isset($v['Latitude']) || !isset($v['Longitude']) || $v['Latitude']<0.065 || $v['Longitude']<0.065){
|
|
|
- continue;
|
|
|
- }
|
|
|
- array_push($arr, $rows[$k]);
|
|
|
+ if (!isset($response['rows'])) {
|
|
|
+ return CatchResponse::success([]);
|
|
|
}
|
|
|
- return array('success'=>true,'message'=>'查询成功','data'=>$arr);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * debug日志
|
|
|
- */
|
|
|
- function debug_log($filename,$data){
|
|
|
- if(Env::get('APP_DEBUG')){
|
|
|
- $file = runtime_path() . '/log/'.date("Y-m-d", time()) ."/".$filename.".log";
|
|
|
- $folder=dirname($file);
|
|
|
- if (!is_dir($folder)){
|
|
|
- mkdir($folder,0777,true);
|
|
|
+
|
|
|
+ foreach ($response['rows'] as $rowData) {
|
|
|
+ // $str=($limit-4000)/2000;
|
|
|
+ $item = [];
|
|
|
+ foreach ($rowData['primary_key'] as $keyItem) {
|
|
|
+ $item[$keyItem[0]] = $keyItem[1];
|
|
|
}
|
|
|
- if(is_array($data)){
|
|
|
- $data = json_encode($data);
|
|
|
+ foreach ($rowData['attribute_columns'] as $colItem) {
|
|
|
+ $item[$colItem[0]] = $colItem[1];
|
|
|
}
|
|
|
- file_put_contents($file, '[' . date('Y-m-d H:i:s') . ']' . $data . PHP_EOL,FILE_APPEND);
|
|
|
+ $item['PassTime'] = date('Y-m-d H:i:s', $item['Timestamp']);
|
|
|
+ $rows[] = $item;
|
|
|
+ $limit--;
|
|
|
+
|
|
|
+ // 处理每一行数据
|
|
|
}
|
|
|
+
|
|
|
+ $startPK = $response['next_start_primary_key'];
|
|
|
+ // 如果 next_start_primary_key 不为空并且 limit > 0 则循环继续
|
|
|
+ }
|
|
|
+ if (!$rows) {
|
|
|
+ return array('success' => true, 'message' => '查询成功', 'data' => []);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * api日志
|
|
|
- */
|
|
|
- function api_log($filename,$data){
|
|
|
-
|
|
|
- $file = runtime_path() . '/log/'.date("Ymd", time()) ."/".$filename.".log";
|
|
|
- $folder=dirname($file);
|
|
|
- if (!is_dir($folder)){
|
|
|
- mkdir($folder,0777,true);
|
|
|
- }
|
|
|
- if(is_array($data)){
|
|
|
- $data = json_encode($data);
|
|
|
- }
|
|
|
- file_put_contents($file, '[' . date('Y-m-d H:i:s') . ']' . $data . PHP_EOL,FILE_APPEND);
|
|
|
-
|
|
|
+ $arr = [];
|
|
|
+
|
|
|
+ foreach ($rows as $k => $v) {
|
|
|
+ if (!isset($v['Latitude']) || !isset($v['Longitude']) || $v['Latitude'] < 0.065 || $v['Longitude'] < 0.065) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ array_push($arr, $rows[$k]);
|
|
|
}
|
|
|
- /**
|
|
|
- *postt请求
|
|
|
- */
|
|
|
- function curl_http_post($data,$url,$ssl){
|
|
|
- $curl = curl_init();
|
|
|
- curl_setopt($curl,CURLOPT_URL,$url);
|
|
|
- if($ssl){
|
|
|
- curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,0);
|
|
|
- curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,1);
|
|
|
- curl_setopt($curl,CURLOPT_SSLVERSION,3);
|
|
|
+ return array('success' => true, 'message' => '查询成功', 'data' => $arr);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * debug日志
|
|
|
+ */
|
|
|
+function debug_log($filename, $data)
|
|
|
+{
|
|
|
+ if (Env::get('APP_DEBUG')) {
|
|
|
+ $file = runtime_path() . '/log/' . date("Y-m-d", time()) . "/" . $filename . ".log";
|
|
|
+ $folder = dirname($file);
|
|
|
+ if (!is_dir($folder)) {
|
|
|
+ mkdir($folder, 0777, true);
|
|
|
}
|
|
|
- // curl_setopt($curl,CURLOPT_USERAGENT,$_SERVER["HTTP_USER_AGENT"]);
|
|
|
- curl_setopt($curl,CURLOPT_AUTOREFERER,1);
|
|
|
- curl_setopt($curl,CURLOPT_POST,1);
|
|
|
- curl_setopt($curl,CURLOPT_POSTFIELDS,$data);
|
|
|
- curl_setopt($curl,CURLOPT_TIMEOUT,30);
|
|
|
- curl_setopt($curl,CURLOPT_HEADER,0);
|
|
|
- curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
|
|
|
- $tmpInfo = curl_exec($curl);
|
|
|
- if(curl_errno($curl)){
|
|
|
- dump(curl_error($curl));
|
|
|
- return false;
|
|
|
+ if (is_array($data)) {
|
|
|
+ $data = json_encode($data);
|
|
|
}
|
|
|
- curl_close($curl);
|
|
|
- return $tmpInfo;
|
|
|
+ file_put_contents($file, '[' . date('Y-m-d H:i:s') . ']' . $data . PHP_EOL, FILE_APPEND);
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * api日志
|
|
|
+ */
|
|
|
+function api_log($filename, $data)
|
|
|
+{
|
|
|
|
|
|
- /**
|
|
|
- * api日志
|
|
|
- */
|
|
|
- function updateDeviceStatus($imei){
|
|
|
- $res=Db::table('devices')->where('imei',$imei)->update(['sync_status'=>1]);
|
|
|
- //var_dump(Db::table('devices')->getLastSql());
|
|
|
-
|
|
|
+ $file = runtime_path() . '/log/' . date("Ymd", time()) . "/" . $filename . ".log";
|
|
|
+ $folder = dirname($file);
|
|
|
+ if (!is_dir($folder)) {
|
|
|
+ mkdir($folder, 0777, true);
|
|
|
}
|
|
|
- //短信管理
|
|
|
- function send_sms_with_config( $mobile, $content, $sms_config, $info ){
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- $config = array();
|
|
|
- /*url示例
|
|
|
+ if (is_array($data)) {
|
|
|
+ $data = json_encode($data);
|
|
|
+ }
|
|
|
+ file_put_contents($file, '[' . date('Y-m-d H:i:s') . ']' . $data . PHP_EOL, FILE_APPEND);
|
|
|
+}
|
|
|
+/**
|
|
|
+ *postt请求
|
|
|
+ */
|
|
|
+function curl_http_post($data, $url, $ssl)
|
|
|
+{
|
|
|
+ $curl = curl_init();
|
|
|
+ curl_setopt($curl, CURLOPT_URL, $url);
|
|
|
+ if ($ssl) {
|
|
|
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
|
|
|
+ curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);
|
|
|
+ curl_setopt($curl, CURLOPT_SSLVERSION, 3);
|
|
|
+ }
|
|
|
+ // curl_setopt($curl,CURLOPT_USERAGENT,$_SERVER["HTTP_USER_AGENT"]);
|
|
|
+ curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
|
|
|
+ curl_setopt($curl, CURLOPT_POST, 1);
|
|
|
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
|
|
+ curl_setopt($curl, CURLOPT_TIMEOUT, 30);
|
|
|
+ curl_setopt($curl, CURLOPT_HEADER, 0);
|
|
|
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
|
+ $tmpInfo = curl_exec($curl);
|
|
|
+ if (curl_errno($curl)) {
|
|
|
+ dump(curl_error($curl));
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ curl_close($curl);
|
|
|
+ return $tmpInfo;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * api日志
|
|
|
+ */
|
|
|
+function updateDeviceStatus($imei)
|
|
|
+{
|
|
|
+ $res = Db::table('devices')->where('imei', $imei)->update(['sync_status' => 1]);
|
|
|
+ //var_dump(Db::table('devices')->getLastSql());
|
|
|
+
|
|
|
+}
|
|
|
+//短信管理
|
|
|
+function send_sms_with_config($mobile, $content, $sms_config, $info)
|
|
|
+{
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $config = array();
|
|
|
+ /*url示例
|
|
|
$url="https://$this->ServerIP:$this->ServerPort/$this->SoftVersion/Accounts/$this->AccountSid/SMS/TemplateSMS?sig=$sig";
|
|
|
*/
|
|
|
- //沙盒环境(应用开发调试):sandboxapp.cloopen.com
|
|
|
- //生产环境(应用上线使用):app.cloopen.com
|
|
|
- $serverIP = 'app.cloopen.com';
|
|
|
-
|
|
|
- //sdk版本号
|
|
|
- $softVersion = '2013-12-26';
|
|
|
- //请求端口,一般为8883
|
|
|
- $serverPort='8883';
|
|
|
- //主账号,对应开官网发者主账号下的 ACCOUNT SID
|
|
|
- $accountSid= $sms_config['accountSid'];
|
|
|
- //$accountSid="8aaf0708754a3ef201755a063f070592";
|
|
|
- $config['accountSid']= $accountSid;
|
|
|
- //密钥
|
|
|
- $config['accountToken'] = $sms_config['accountToken'];
|
|
|
- //$config['accountToken'] = "324fb91d40cf472580dc8dc4d9a3e0d5";
|
|
|
- //应用Id,在官网应用列表中点击应用,对应应用详情中的APP ID
|
|
|
- $config['appId'] = $sms_config['appId'];
|
|
|
- //$config['appId'] = "8aaf070875774c6d0175910e26fc0bf9";
|
|
|
- //时间戳
|
|
|
- $batch = date("YmdHis");
|
|
|
- //验证信息编码
|
|
|
- $config['authen'] = base64_encode($accountSid . ":" . $batch);
|
|
|
- //加密REST API验证参数
|
|
|
- $sig = strtoupper(md5($accountSid . $config['accountToken'] . $batch));
|
|
|
- //拼接url
|
|
|
- $config['api_send_url'] = "https://$serverIP:$serverPort/$softVersion/Accounts/$accountSid/SMS/TemplateSMS?sig=".$sig;
|
|
|
-
|
|
|
- $postArr = array (
|
|
|
- 'to'=>$mobile,
|
|
|
- 'templateId' => $content['tplno'],
|
|
|
- 'appId'=>$config['appId'],
|
|
|
- 'datas'=>$content['tpldata'],
|
|
|
- );
|
|
|
- $postArr = json_encode($postArr);
|
|
|
- $authen = $config['authen'];
|
|
|
- $header = array("Accept:application/json","Content-Type:application/json;charset=utf-8","Authorization:$authen");
|
|
|
- $url = $config['api_send_url'];
|
|
|
- //$result = $this->curlPost( $url , $postArr, $header);
|
|
|
- //初始化curl
|
|
|
- $ch = curl_init();
|
|
|
- //参数设置
|
|
|
- $res= curl_setopt ($ch, CURLOPT_URL,$url);
|
|
|
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
|
|
|
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
|
|
- curl_setopt ($ch, CURLOPT_HEADER, 0);
|
|
|
- curl_setopt($ch, CURLOPT_POST, 1);
|
|
|
- curl_setopt($ch, CURLOPT_POSTFIELDS, $postArr);
|
|
|
- curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
- curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
|
|
|
- $result = curl_exec ($ch);
|
|
|
- curl_close($ch);
|
|
|
-
|
|
|
- $result = json_decode($result,true);
|
|
|
- //var_dump($result);
|
|
|
- $data=array(
|
|
|
- 'recipient'=>$mobile,
|
|
|
- 'content'=>$content['info'],
|
|
|
- // 'type'=>'sms',
|
|
|
- 'created_at'=>time(),
|
|
|
- 'creator_id'=>0,
|
|
|
- // 'sent_time'=>time(),
|
|
|
- );
|
|
|
- if($result['statusCode']==='000000'){
|
|
|
- $data['sent_result']='发送成功';
|
|
|
- $res = Db::name('sms_send_log')->insert($data);
|
|
|
- return array('success'=>true,'message'=>'发送成功');
|
|
|
- }else{
|
|
|
- $data['sent_result']=json_encode($result,JSON_UNESCAPED_UNICODE);
|
|
|
- $res = Db::name('sms_send_log')->insert($data);
|
|
|
- return array('success'=>false,'errorCode'=>$result['statusCode'],'message'=>$result['statusMsg'],'data'=>$data);
|
|
|
- }
|
|
|
-
|
|
|
+ //沙盒环境(应用开发调试):sandboxapp.cloopen.com
|
|
|
+ //生产环境(应用上线使用):app.cloopen.com
|
|
|
+ $serverIP = 'app.cloopen.com';
|
|
|
+
|
|
|
+ //sdk版本号
|
|
|
+ $softVersion = '2013-12-26';
|
|
|
+ //请求端口,一般为8883
|
|
|
+ $serverPort = '8883';
|
|
|
+ //主账号,对应开官网发者主账号下的 ACCOUNT SID
|
|
|
+ $accountSid = $sms_config['accountSid'];
|
|
|
+ //$accountSid="8aaf0708754a3ef201755a063f070592";
|
|
|
+ $config['accountSid'] = $accountSid;
|
|
|
+ //密钥
|
|
|
+ $config['accountToken'] = $sms_config['accountToken'];
|
|
|
+ //$config['accountToken'] = "324fb91d40cf472580dc8dc4d9a3e0d5";
|
|
|
+ //应用Id,在官网应用列表中点击应用,对应应用详情中的APP ID
|
|
|
+ $config['appId'] = $sms_config['appId'];
|
|
|
+ //$config['appId'] = "8aaf070875774c6d0175910e26fc0bf9";
|
|
|
+ //时间戳
|
|
|
+ $batch = date("YmdHis");
|
|
|
+ //验证信息编码
|
|
|
+ $config['authen'] = base64_encode($accountSid . ":" . $batch);
|
|
|
+ //加密REST API验证参数
|
|
|
+ $sig = strtoupper(md5($accountSid . $config['accountToken'] . $batch));
|
|
|
+ //拼接url
|
|
|
+ $config['api_send_url'] = "https://$serverIP:$serverPort/$softVersion/Accounts/$accountSid/SMS/TemplateSMS?sig=" . $sig;
|
|
|
+
|
|
|
+ $postArr = array(
|
|
|
+ 'to' => $mobile,
|
|
|
+ 'templateId' => $content['tplno'],
|
|
|
+ 'appId' => $config['appId'],
|
|
|
+ 'datas' => $content['tpldata'],
|
|
|
+ );
|
|
|
+ $postArr = json_encode($postArr);
|
|
|
+ $authen = $config['authen'];
|
|
|
+ $header = array("Accept:application/json", "Content-Type:application/json;charset=utf-8", "Authorization:$authen");
|
|
|
+ $url = $config['api_send_url'];
|
|
|
+ //$result = $this->curlPost( $url , $postArr, $header);
|
|
|
+ //初始化curl
|
|
|
+ $ch = curl_init();
|
|
|
+ //参数设置
|
|
|
+ $res = curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
|
|
|
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
|
|
+ curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
|
+ curl_setopt($ch, CURLOPT_POST, 1);
|
|
|
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $postArr);
|
|
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
|
|
|
+ $result = curl_exec($ch);
|
|
|
+ curl_close($ch);
|
|
|
+
|
|
|
+ $result = json_decode($result, true);
|
|
|
+ //var_dump($result);
|
|
|
+ $data = array(
|
|
|
+ 'recipient' => $mobile,
|
|
|
+ 'content' => $content['info'],
|
|
|
+ // 'type'=>'sms',
|
|
|
+ 'created_at' => time(),
|
|
|
+ 'creator_id' => 0,
|
|
|
+ // 'sent_time'=>time(),
|
|
|
+ );
|
|
|
+ if ($result['statusCode'] === '000000') {
|
|
|
+ $data['sent_result'] = '发送成功';
|
|
|
+ $res = Db::name('sms_send_log')->insert($data);
|
|
|
+ return array('success' => true, 'message' => '发送成功');
|
|
|
+ } else {
|
|
|
+ $data['sent_result'] = json_encode($result, JSON_UNESCAPED_UNICODE);
|
|
|
+ $res = Db::name('sms_send_log')->insert($data);
|
|
|
+ return array('success' => false, 'errorCode' => $result['statusCode'], 'message' => $result['statusMsg'], 'data' => $data);
|
|
|
}
|
|
|
+}
|
|
|
|
|
|
|
|
|
- function get_sms_config( $type ){
|
|
|
- $key="wxt_sms_send_config_".$type;
|
|
|
- $sms_cache_config =S($key);
|
|
|
-
|
|
|
- $sms_config=array();
|
|
|
-
|
|
|
- if(!$sms_cache_config){
|
|
|
- $config_id=Db::name('sms_config')->where(array('name'=>$type,'pid'=>'0'))->getField('id');
|
|
|
- if(!$config_id){
|
|
|
- return array('result'=>'fail','message'=>'未配置'.$type);
|
|
|
- }
|
|
|
- $config_list=Db::name('sms_config')->where(array('pid'=>$config_id))->select();
|
|
|
- if(!$config_list){
|
|
|
- return array('result'=>'fail','message'=>'未配置参数'.$type);
|
|
|
- }
|
|
|
- foreach($config_list as $val){
|
|
|
- $sms_config[$val['key']]=$val['value'];
|
|
|
- }
|
|
|
+function get_sms_config($type)
|
|
|
+{
|
|
|
+ $key = "wxt_sms_send_config_" . $type;
|
|
|
+ $sms_cache_config = S($key);
|
|
|
+
|
|
|
+ $sms_config = array();
|
|
|
|
|
|
- S($key,json_encode($sms_config),60);
|
|
|
- }else{
|
|
|
- $sms_config=json_decode($sms_cache_config,true);
|
|
|
+ if (!$sms_cache_config) {
|
|
|
+ $config_id = Db::name('sms_config')->where(array('name' => $type, 'pid' => '0'))->getField('id');
|
|
|
+ if (!$config_id) {
|
|
|
+ return array('result' => 'fail', 'message' => '未配置' . $type);
|
|
|
+ }
|
|
|
+ $config_list = Db::name('sms_config')->where(array('pid' => $config_id))->select();
|
|
|
+ if (!$config_list) {
|
|
|
+ return array('result' => 'fail', 'message' => '未配置参数' . $type);
|
|
|
+ }
|
|
|
+ foreach ($config_list as $val) {
|
|
|
+ $sms_config[$val['key']] = $val['value'];
|
|
|
}
|
|
|
-
|
|
|
- return $sms_config;
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * 返回JSON成功信息
|
|
|
- * message: 消息文本
|
|
|
- * data: 额外数据
|
|
|
- * @time 2022年06月09日 14:22
|
|
|
- */
|
|
|
- function json_success($message,$data=''){
|
|
|
- echo json_encode(array('success' => true, 'message' => $message, 'data' => $data),JSON_UNESCAPED_UNICODE);
|
|
|
- exit;
|
|
|
+ S($key, json_encode($sms_config), 60);
|
|
|
+ } else {
|
|
|
+ $sms_config = json_decode($sms_cache_config, true);
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 失败JSON成功信息
|
|
|
- * message: 消息文本
|
|
|
- * data: 额外数据
|
|
|
- * @time 2022年06月09日 14:22
|
|
|
- */
|
|
|
- function json_fail($message,$data = ''){
|
|
|
- echo json_encode(array('success' => false, 'message' => $message, 'data' => $data),JSON_UNESCAPED_UNICODE);
|
|
|
- exit;
|
|
|
- }
|
|
|
+
|
|
|
+ return $sms_config;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 返回JSON成功信息
|
|
|
+ * message: 消息文本
|
|
|
+ * data: 额外数据
|
|
|
+ * @time 2022年06月09日 14:22
|
|
|
+ */
|
|
|
+function json_success($message, $data = '')
|
|
|
+{
|
|
|
+ echo json_encode(array('success' => true, 'message' => $message, 'data' => $data), JSON_UNESCAPED_UNICODE);
|
|
|
+ exit;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 失败JSON成功信息
|
|
|
+ * message: 消息文本
|
|
|
+ * data: 额外数据
|
|
|
+ * @time 2022年06月09日 14:22
|
|
|
+ */
|
|
|
+function json_fail($message, $data = '')
|
|
|
+{
|
|
|
+ echo json_encode(array('success' => false, 'message' => $message, 'data' => $data), JSON_UNESCAPED_UNICODE);
|
|
|
+ exit;
|
|
|
+}
|
|
|
+/**
|
|
|
+ * @Descripttion: 获取当前毫秒级时间戳
|
|
|
+ * @name: likang
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+function msectime()
|
|
|
+{
|
|
|
+ list($msec, $sec) = explode(' ', microtime());
|
|
|
+ $msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
|
|
|
+ return $msectime;
|
|
|
+}
|