Browse Source

Weenier utc项目部署 0629

wesmiler 3 years ago
parent
commit
2d756f9ae4

+ 73 - 22
app/Helpers/function.php

@@ -32,27 +32,78 @@ if (!function_exists('isPhone')) {
     }
 }
 
-/**
- * 金钱格式化小数点
- * @param $money
- * @param int $decimal 小数点位数,默认系统配置2位
- * @return float
- */
-function moneyFormat($money, $decimal=null){
-    $formatConfig = [];
-    $charset = !empty($formatConfig['charset'])? trim($formatConfig['charset']) : 'utf-8';
-    if($decimal === null){
-        $decimal = isset($formatConfig['moneyDecimal'])? intval($formatConfig['moneyDecimal']): 2;
+
+if (!function_exists('moneyFormat')) {
+    /**
+     * 金钱格式化小数点
+     * @param $money
+     * @param int $decimal 小数点位数,默认系统配置2位
+     * @return float
+     */
+    function moneyFormat($money, $decimal = null)
+    {
+        $formatConfig = [];
+        $charset = !empty($formatConfig['charset']) ? trim($formatConfig['charset']) : 'utf-8';
+        if ($decimal === null) {
+            $decimal = isset($formatConfig['moneyDecimal']) ? intval($formatConfig['moneyDecimal']) : 2;
+        }
+        $money = round($money, $decimal + 1);
+        $data = explode('.', $money);
+        $money = isset($data[0]) ? $data[0] : 0;
+        $float = isset($data[1]) ? $data[1] : '';
+        $len = $float ? mb_strlen($float, $charset) : 0;
+
+        $decimal = $decimal >= 0 ? intval($decimal) : 2;
+        $num1 = isset($data[1]) ? $data[1] : '';
+        $float = $len >= $decimal ? mb_substr($num1, 0, $decimal, $charset) : $float . str_repeat('0', $decimal - $len);
+        $money = $money . '.' . $float;
+        return number_format($money, $decimal, '.', '');
+    }
+}
+
+
+if (!function_exists('paramsFormat')) {
+    /**
+     * 格式化请求数组参数为&连接字符串
+     * @param array $data 参数数组
+     * @param false $filter 是否过滤空值字段
+     * @return string
+     */
+    function paramsFormat(array $data, $filter=false){
+        $result = [];
+        ksort($data);
+        foreach($data as $k => $v){
+            if($filter && !empty($v) || !$filter){
+                $result[] = "{$k}={$v}";
+            }
+        }
+
+        return implode('&', $result);
+    }
+}
+
+
+if (!function_exists('xmlToArray')) {
+    /**
+     * xml转数组
+     * @param $xml
+     * @return array
+     */
+    function xmlToArray($xml){
+        if(!$xml){
+            return [];
+        }
+
+        $result = [];
+        $xml = (array)simplexml_load_string($xml);
+        foreach($xml as $k => $v){
+            if(!is_object($v)){
+                $result[$k] = $v;
+            }else{
+                $result[$k] = xmlToArray((array)$v);
+            }
+        }
+
+        return $result;
     }
-    $money = round($money, $decimal+1);
-    $data = explode('.', $money);
-    $money = isset($data[0])? $data[0] : 0;
-    $float = isset($data[1])? $data[1] : '';
-    $len = $float? mb_strlen($float, $charset) : 0;
-
-    $decimal = $decimal>=0? intval($decimal) : 2;
-    $num1 = isset($data[1])? $data[1] : '';
-    $float = $len>=$decimal? mb_substr($num1, 0, $decimal, $charset) : $float.str_repeat('0', $decimal-$len);
-    $money = $money.'.'.$float;
-    return number_format($money, $decimal, '.', '');
 }

+ 4 - 1
app/Http/Controllers/Api/IndexController.php

@@ -6,6 +6,7 @@ use App\Helpers\Jwt;
 use App\Http\Validator\MemberValidator;
 use App\Services\Api\AdService;
 use App\Services\Api\MemberService;
+use App\Services\ConfigService;
 use App\Services\EmailService;
 use App\Services\RedisService;
 use App\Services\SmsService;
@@ -37,8 +38,10 @@ class IndexController extends webApp
             'middle'=> AdService::make()->getList(2, 1),
         ];
         // 交易参数
+        $trade = ConfigService::make()->getConfigByGroup(5);
         $trade = [
-            'price'=> rand(5, 10)+(rand(10,50)/100),
+            'buy_price'=> isset($trade['usdt_buy_price'])? floatval($trade['usdt_buy_price']) : '0.00',
+            'sell_price'=> isset($trade['usdt_sell_price'])? floatval($trade['usdt_sell_price']) : '0.00',
             'total'=> rand(100000,999999)+(rand(10,50)/100),
             'count'=> rand(1000,9999),
             'rate'=> rand(10,90)+(rand(10,50)/100),

+ 1 - 1
app/Services/EmailService.php

@@ -93,7 +93,7 @@ class EmailService extends BaseService
             // 发送频繁
             if (RedisService::get($cacheKey . '_lock')) {
                 $this->error = '1014';
-//                return false;
+                return false;
             }
 
             $title = isset($this->config['mail_title_' . $scene]['value']) && $this->config['mail_title_' . $scene]['value'] ? $this->config['mail_title_' . $scene]['value'] : "UTC网站注册邮箱验证码";

+ 64 - 9
app/Services/SmsService.php

@@ -24,28 +24,83 @@ class SmsService extends BaseService
 {
     // 静态对象
     protected static $instance = null;
+
+    /**
+     * 初始化配置
+     * @return bool
+     */
+    public function __construct()
+    {
+        $this->config = ConfigService::make()->getConfigByGroup(2);
+        if (empty($this->config)) {
+            return false;
+        }
+    }
+
     /**
      * 静态入口
      * @return static|null
      */
     public static function make()
     {
-        if(!self::$instance){
+        if (!self::$instance) {
             self::$instance = (new static());
         }
         return self::$instance;
     }
+
     /**
      * 发送手机短信
      * @param $email
      * @param string $scene 场景:默认reg-注册
      * @return bool
      */
-    public function sendCode($mobile, $scene='reg')
+    public function sendCode($mobile, $scene = 'reg')
     {
-        return true;
+        try {
+            $cacheKey = "stores:codes:sms_{$scene}:" . substr($mobile, -3, 3) . '_' . md5($mobile);
+            $apiUrl = isset($this->config['sms_api_url']['value']) ? $this->config['sms_api_url']['value'] : '';
+            if (empty($mobile) || empty($apiUrl)) {
+                return false;
+            }
+
+            if (RedisService::get($cacheKey . '_lock')) {
+                $this->error = '1014';
+                return false;
+            }
+
+            // 生成验证码
+            $code = rand(100000, 999999);
+            $template = isset($this->config['sms_template_' . $scene]['value']) && $this->config['sms_template_' . $scene]['value'] ? $this->config['sms_template_' . $scene]['value'] : '您的验证码是:{code},请在5分钟内使用!!!';
+            $template = str_replace('{code}', $code, $template);
+
+            $data = [
+                'userid' => isset($this->config['sms_id']['value']) ? $this->config['sms_id']['value'] : '',
+                'account' => isset($this->config['sms_account']['value']) ? $this->config['sms_account']['value'] : '',
+                'password' => isset($this->config['sms_password']['value']) ? $this->config['sms_password']['value'] : '',
+                'mobile' => $mobile,
+                'content' => $template,
+                'action' => 'send',
+                'sendTime' => '', // 发送时间:空立即发送
+            ];
+
+            RedisService::set($cacheKey . '_lock', ['mobile' => $mobile, 'code' => $code, 'date' => date('Y-m-d H:i:s')], rand(10, 20));
+            $result = curl_post($apiUrl, $data);
+            $result = $result ? xmlToArray($result) : [];
+            $status = isset($result['returnstatus']) ? $result['returnstatus'] : '';
+            if ($status == 'Success') {
+                RedisService::set($cacheKey, ['mobile' => $mobile, 'code' => $code, 'date' => date('Y-m-d H:i:s')], 300);
+                return true;
+            }
+
+            return false;
+        } catch (\Exception $exception) {
+            $this->error = $exception->getMessage();
+            return false;
+        }
     }
 
+
     /**
      * 验证手机短信
      * @param $mobile
@@ -53,18 +108,18 @@ class SmsService extends BaseService
      * @param string $scene 场景:默认reg-注册
      * @return bool
      */
-    public function check($mobile, $code, $scene='reg')
+    public function check($mobile, $code, $scene = 'reg')
     {
-        $cacheKey = "stores:codes:mobile_{$scene}:" . md5($mobile);
+        $cacheKey = "stores:codes:sms_{$scene}:". substr($mobile, -3, 3) . '_' . md5($mobile);
         $codeData = RedisService::get($cacheKey);
-        $checkCode = isset($codeData['code'])? $codeData['code'] : 0;
-        $checkMobile = isset($codeData['mobile'])? $codeData['mobile'] : '';
-        if(empty($codeData) || empty($checkCode)){
+        $checkCode = isset($codeData['code']) ? $codeData['code'] : 0;
+        $checkMobile = isset($codeData['mobile']) ? $codeData['mobile'] : '';
+        if (empty($codeData) || empty($checkCode)) {
             $this->error = 2010;
             return false;
         }
 
-        if($checkMobile != $mobile || $checkCode != $code){
+        if ($checkMobile != $mobile || $checkCode != $code) {
             $this->error = 2006;
             return false;
         }