|
@@ -11,27 +11,63 @@ use think\facade\Log;
|
|
|
class SmsService
|
|
|
{
|
|
|
|
|
|
+// public function send($mobile, $code, $content_param = [])
|
|
|
+// {
|
|
|
+// if (env('APP_DEBUG')) {
|
|
|
+// return ['code' => 0];
|
|
|
+// }
|
|
|
+//
|
|
|
+// $message = MessageTemplate::where('code', $code)->find();
|
|
|
+// if (empty($message)) {
|
|
|
+// Log::error('短信模板不存在:' . $code);
|
|
|
+// return ['code' => 1, 'msg' => '模板不存在'];
|
|
|
+// }
|
|
|
+//
|
|
|
+// $msg = $message['content'];
|
|
|
+// if (!empty($content_param)) {
|
|
|
+// foreach ($content_param as $k => $v) {
|
|
|
+// $msg = str_replace('{$' . ($k + 1) . '}', $v, $msg);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// $sms = new Chuanglan();
|
|
|
+// $sms->send($mobile, ['message' => $msg]);
|
|
|
+//
|
|
|
+// return ['code' => 0];
|
|
|
+// }
|
|
|
+
|
|
|
public function send($mobile, $code, $content_param = [])
|
|
|
{
|
|
|
- if (env('APP_DEBUG')) {
|
|
|
- return ['code' => 0];
|
|
|
- }
|
|
|
- $message = MessageTemplate::where('code', $code)->find();
|
|
|
- if (empty($message)) {
|
|
|
- Log::error('短信模板不存在:' . $code);
|
|
|
- return ['code' => 1, 'msg' => '模板不存在'];
|
|
|
- }
|
|
|
+ $url = "https://lw_test.jinjianghc.com/api/sms/send";
|
|
|
+ $token = "L1mq09OB68be4b4526092";
|
|
|
+// $url = "http://bd.lwtest.com/api/sms/send";
|
|
|
+// $token = "7ec987cb2daf4c44a84ff1f145c51f2b";
|
|
|
+ $postArr = ['mobile'=>$mobile,'template_code'=>$code,'template_param'=>$content_param];
|
|
|
+ $postFields = json_encode($postArr);
|
|
|
|
|
|
- $msg = $message['content'];
|
|
|
- if (!empty($content_param)) {
|
|
|
- foreach ($content_param as $k => $v) {
|
|
|
- $msg = str_replace('{$' . ($k + 1) . '}', $v, $msg);
|
|
|
- }
|
|
|
- }
|
|
|
- $sms = new Chuanglan();
|
|
|
- $sms->send($mobile, ['message' => $msg]);
|
|
|
+ $ch = curl_init();
|
|
|
+ curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
+ curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
|
|
+ 'Content-Type: application/json; charset=utf-8', //json版本需要填写 Content-Type: application/json;
|
|
|
+ 'token:'.$token
|
|
|
+ ]
|
|
|
+ );
|
|
|
+ curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); //若果报错 name lookup timed out 报错时添加这一行代码
|
|
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
+ curl_setopt($ch, CURLOPT_POST, 1);
|
|
|
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
|
|
|
+ curl_setopt($ch, CURLOPT_TIMEOUT, 60);
|
|
|
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
|
|
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
|
|
+ $ret = curl_exec($ch);
|
|
|
+ curl_close($ch);
|
|
|
+ $rsp = json_decode($ret, true);
|
|
|
|
|
|
- return ['code' => 0];
|
|
|
+ if ($rsp['code'] != 0) {
|
|
|
+ Log::record('短信发送失败:' . json_encode($rsp) . "。原始参数:" . json_encode($postArr));
|
|
|
+ return ['code' => 1, 'msg' => $rsp['errorMsg']];
|
|
|
+ } else {
|
|
|
+ return ['code' => 0];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public function examineSend($code, $content_param = [])
|