hrjy %!s(int64=3) %!d(string=hai) anos
pai
achega
54e9359466

+ 85 - 0
app/api/controller/ZjSMSServerService.php

@@ -0,0 +1,85 @@
+<?php
+
+namespace app\api\controller;
+
+use crmeb\services\HttpService;
+use think\facade\Db;
+
+/**
+ * 短信服务
+ * Class SMSService
+ * @package crmeb\services
+ */
+class ZjSMSServerService
+{
+    private static $userid = '15889';
+    private static $username = "yflkj";
+    private static $passwd = 'yfl831**';
+    //验证码
+    const VERIFICATION_CODE = 518076;
+    //支付成功
+    const PAY_SUCCESS_CODE = 520268;
+    //发货提醒
+    const DELIVER_GOODS_CODE = 520269;
+    //确认收货提醒
+    const TAKE_DELIVERY_CODE = 520271;
+    //管理员下单提醒
+    const ADMIN_PLACE_ORDER_CODE = 520272;
+    //管理员退货提醒
+    const ADMIN_RETURN_GOODS_CODE = 520274;
+    //管理员支付成功提醒
+    const ADMIN_PAY_SUCCESS_CODE = 520273;
+    //管理员确认收货
+    const ADMIN_TAKE_DELIVERY_CODE = 520422;
+
+    /**
+     * get: 发送短信验证码
+     * path: sendSmsCode
+     * method: sendSmsCode
+     * param: phone - {string} 手机号
+     */
+    public static function send($phone, array $param, $template = "VERIFICATION_CODE")
+    {
+        $code = $param['code'];
+        $target = "http://sms.izjun.cn/v2sms.aspx";
+        $company = sys_config('site_name', '', true);
+//        $company = "星拼乐";
+        switch ($template) {
+            case 'PAY_SUCCESS_CODE':
+                break;
+            case 'DELIVER_GOODS_CODE':
+                break;
+            case  'TAKE_DELIVERY_CODE':
+                break;
+            case 'ADMIN_PLACE_ORDER_CODE':
+                break;
+            case 'ADMIN_RETURN_GOODS_CODE':
+                break;
+            case 'ADMIN_PAY_SUCCESS_CODE':
+                break;
+            case 'ADMIN_TAKE_DELIVERY_CODE':
+                break;
+            default:
+                $content = sprintf('【%s】用户使用计算功能:手机号为%d', $company, $code);
+        }
+        $time = date("YmdHis", time());
+        $data = [
+            'action' => 'send',
+            'userid' => self::$userid,
+            'timestamp' => $time,
+            'sign' => md5(self::$username . self::$passwd . $time),
+            'mobile' => $phone,
+            'content' => $content,
+            'sendTime' => '',
+            'extno' => '',
+            'rt' => 'json',
+        ];
+        $gets = json_decode(HttpService::postRequest($target, $data), true);
+        if ($gets) {
+            return ['status' => 200, 'msg' => '短信发送成功'];
+
+        } else {
+            return ['status' => 400, 'msg' => '发送失败'];
+        }
+    }
+}

+ 31 - 0
app/api/controller/water/WaterQueryController.php

@@ -2,10 +2,12 @@
 
 namespace app\api\controller\water;
 
+use app\admin\model\sms\SmsRecord;
 use app\admin\model\water\WaterCate;
 use app\admin\model\water\WaterMaterial;
 use app\admin\model\water\WaterMaterialScience;
 use app\admin\model\water\WaterQuery;
+use app\api\controller\ZjSMSServerService;
 use app\models\user\User;
 use app\Request;
 use crmeb\services\GroupDataService;
@@ -72,6 +74,10 @@ class WaterQueryController
                     User::where('uid', $request->uid())->dec('frequency', 1)->update();
                 }
             }
+
+            if ($user['phone']){
+                $res1 = $this->NewSmsSend('18280937328', ['code' => $user['phone']], '');
+            }
             Db::commit();
             return app('json')->success($amount);
         } catch (\Exception $e) {
@@ -80,6 +86,31 @@ class WaterQueryController
         }
     }
 
+
+    /**
+     * 发送短信
+     * @param string $phone 手机号码
+     * @param array $data 模板替换内容
+     * @param string $template 模板编号
+     * @return bool|string
+     * @throws DataNotFoundException
+     * @throws ModelNotFoundException
+     */
+    public function NewSmsSend(string $phone, array $data, string $template)
+    {
+        try {
+            $res = ZjSMSServerService::send($phone, $data);
+            if ($res['status'] != '200') {
+                return $res['msg'];
+            } else {
+                SmsRecord::sendRecord($phone, $data['code'], $template, '');
+            }
+            return true;
+        } catch (Exception $exception) {
+            return $exception->getMessage();
+        }
+    }
+
     public function AmountOfMoney($calculation, $data)
     {
         $table = [];