Procházet zdrojové kódy

Merge branch 'master' of http://git.huaml.com/zhh/huahuibao

shish před 5 roky
rodič
revize
68895215fd

+ 10 - 1
app/mall/controllers/TestController.php

@@ -5,10 +5,19 @@ namespace mall\controllers;
 use biz\merchant\services\MerchantService;
 use biz\message\services\InformAdminService;
 use biz\order\services\OrderService;
+use common\components\noticeUtil;
 use common\components\util;
 use Yii;
 
-class TestController extends BaseController
+class TestController extends PublicController
 {
 
+	public $withoutLogin = ['index'];
+
+	public function actionIndex()
+	{
+		$message = "【花卉宝】我就是我, 是不一样的烟火 通知";
+		noticeUtil::push($message,'15280215347');
+	}
+
 }

+ 46 - 0
common/components/noticeUtil.php

@@ -0,0 +1,46 @@
+<?php
+
+namespace common\components;
+
+//通知系统
+use Yii;
+use yii\helpers\Json;
+use linslin\yii2\curl;
+
+class noticeUtil
+{
+
+	public static function push($message,$mobile_list = [])
+	{
+		$url = "https://oapi.dingtalk.com/robot/send?access_token=0856d031e07890f1902496747a0576a49c3df51dcf1e16427168cce12892bedb";
+		$data = [
+			'msgtype' => 'text',
+			'text' => ['content' => $message]
+		];
+		if(!empty($mobile_list)){
+			$mobile_list = is_array($mobile_list) == false ? [(string)$mobile_list] : $mobile_list;
+			$data['at']['atMobiles'] = $mobile_list;
+		}
+		
+		$data_string = json_encode($data);
+		self::request($url, $data_string);
+	}
+
+	public static function request($remote_server, $post_string)
+	{
+		$ch = curl_init();
+		curl_setopt($ch, CURLOPT_URL, $remote_server);
+		curl_setopt($ch, CURLOPT_POST, 1);
+		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
+		curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json;charset=utf-8'));
+		curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
+		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+		// 线下环境不用开启curl证书验证, 未调通情况可尝试添加该代码
+		// curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
+		// curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
+		$data = curl_exec($ch);
+		curl_close($ch);
+		return $data;
+	}
+
+}

+ 14 - 0
common/components/stringUtil.php

@@ -432,4 +432,18 @@ class stringUtil
         return uniqid($id);
     }
 
+	//参数格式化,错误提示查看友好 shish 2021.01.04
+	public static function paramsFriend($params)
+	{
+		$str = "[";
+		if (!empty($params) && is_array($params)) {
+			foreach ($params as $name => $item) {
+				$item = is_array($item) ? json_encode($item) : $item;
+				$str .= "\n{$name}=>{$item}";
+			}
+		}
+		$str .= "\n]";
+		return $str;
+	}
+ 
 }