|
@@ -0,0 +1,56 @@
|
|
|
+<?php
|
|
|
+/**
|
|
|
+ * 手机短信类
|
|
|
+ */
|
|
|
+
|
|
|
+namespace lk;
|
|
|
+
|
|
|
+use app\common\model\SettingModel;
|
|
|
+use think\facade\Log;
|
|
|
+
|
|
|
+class Lk
|
|
|
+{
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 短信发送
|
|
|
+ * @param $mobile
|
|
|
+ * @param $smslog_param
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function send($mobile, $smslog_param)
|
|
|
+ {
|
|
|
+ $config = SettingModel::getConfigValue(['sms_lk_secretKey', 'sms_lk_secretName']);
|
|
|
+ $url = "https://api.028lk.com/Sms/Api/Send";
|
|
|
+ $data = [
|
|
|
+ "SecretName" => $config['sms_lk_secretName'],
|
|
|
+ "SecretKey" => $config['sms_lk_secretKey'],
|
|
|
+ "Mobile" => $mobile,
|
|
|
+ "Content" => $smslog_param['message'],
|
|
|
+ ];
|
|
|
+ $postData = json_encode($data,JSON_UNESCAPED_UNICODE);
|
|
|
+ $postHeader = [
|
|
|
+ "Content-Type: application/json; charset=utf-8",
|
|
|
+ "Content-Length:" . strlen($postData),
|
|
|
+ ];
|
|
|
+
|
|
|
+ //POST方式请求
|
|
|
+ $curl = curl_init();
|
|
|
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查 -https
|
|
|
+ curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, true);
|
|
|
+ curl_setopt($curl, CURLOPT_URL, $url);
|
|
|
+ curl_setopt($curl, CURLOPT_POST, 1);
|
|
|
+ curl_setopt($curl, CURLOPT_HEADER, 0);
|
|
|
+ curl_setopt($curl, CURLOPT_HTTPHEADER,$postHeader);
|
|
|
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
|
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
|
|
|
+ $result = curl_exec($curl);
|
|
|
+ curl_close($curl);
|
|
|
+
|
|
|
+ if (isset($rsp['code']) && $rsp['code'] == 0) {
|
|
|
+ return ['code' => 0];
|
|
|
+ } else {
|
|
|
+ Log::error('短信发送失败:' . $result . "。原始参数:" . $postData);
|
|
|
+ return ['code' => 1, 'msg' => "错误码:" . $rsp['errCode']];
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|