mirror of
				https://gitee.com/zoujingli/ThinkAdmin.git
				synced 2025-10-31 04:02:07 +08:00 
			
		
		
		
	[更新]去除不需要的短信服务功能
This commit is contained in:
		
							parent
							
								
									f22806576f
								
							
						
					
					
						commit
						39d6598063
					
				| @ -15,7 +15,6 @@ | |||||||
| namespace app\admin\controller; | namespace app\admin\controller; | ||||||
| 
 | 
 | ||||||
| use controller\BasicAdmin; | use controller\BasicAdmin; | ||||||
| use service\ExtendService; |  | ||||||
| use service\LogService; | use service\LogService; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
| @ -72,17 +71,4 @@ class Config extends BasicAdmin | |||||||
|         return $this->index(); |         return $this->index(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|      * 短信参数配置 |  | ||||||
|      * @return string |  | ||||||
|      * @throws \think\Exception |  | ||||||
|      * @throws \think\exception\PDOException |  | ||||||
|      */ |  | ||||||
|     public function sms() |  | ||||||
|     { |  | ||||||
|         $this->title = '短信服务配置'; |  | ||||||
|         $this->assign('result', ExtendService::querySmsBalance()); |  | ||||||
|         return $this->index(); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,41 +0,0 @@ | |||||||
| {extend name="admin@public/content"} |  | ||||||
| 
 |  | ||||||
| {block name="content"} |  | ||||||
| <form onsubmit="return false;" action="{:request()->url()}" data-auto="true" method="post" class='form-horizontal layui-form padding-30'> |  | ||||||
| 
 |  | ||||||
|     <div class="form-group"> |  | ||||||
|         <label class="col-sm-2 control-label">State <span class="nowrap">(账号状态)</span></label> |  | ||||||
|         <div class='col-sm-8'> |  | ||||||
|             <input disabled class="layui-input layui-bg-gray" value="{if $result.code}账号正常,短信剩余 {$result.num} 条{else}{$result.msg}{/if}"> |  | ||||||
|             <p class="help-block">肋通SMS接口状态,若短信剩余条数不足时,请提前充值。</p> |  | ||||||
|         </div> |  | ||||||
|     </div> |  | ||||||
| 
 |  | ||||||
|     <div class="form-group"> |  | ||||||
|         <label class="col-sm-2 control-label">Username <span class="nowrap">(平台账号)</span></label> |  | ||||||
|         <div class='col-sm-8'> |  | ||||||
|             <input type="text" name="sms_username" autocomplete="off" required="required" value="{:sysconf('sms_username')}" |  | ||||||
|                    title="请输入助通SMS接口平台账号" placeholder="请输入助通SMS接口平台账号" class="layui-input"> |  | ||||||
|             <p class="help-block">助通SMS接口平台账号,平台管理 <a target="_blank" href="http://client.ztsms.cn">登录平台</a>。</p> |  | ||||||
|         </div> |  | ||||||
|     </div> |  | ||||||
| 
 |  | ||||||
|     <div class="form-group"> |  | ||||||
|         <label class="col-sm-2 control-label">Password <span class="nowrap">(平台密码)</span></label> |  | ||||||
|         <div class='col-sm-8'> |  | ||||||
|             <input type="text" name="sms_password" autocomplete="off" required="required" value="{:sysconf('sms_password')}" |  | ||||||
|                    title="请输入助通SMS接口平台密码" placeholder="请输入助通SMS接口平台密码" class="layui-input"> |  | ||||||
|             <p class="help-block">助通SMS接口平台密码,需要在助通平台修改。</p> |  | ||||||
|         </div> |  | ||||||
|     </div> |  | ||||||
| 
 |  | ||||||
|     <div class="hr-line-dashed"></div> |  | ||||||
| 
 |  | ||||||
|     <div class="col-sm-4 col-sm-offset-2"> |  | ||||||
|         <div class="layui-form-item text-center"> |  | ||||||
|             <button class="layui-btn" type="submit">保存配置</button> |  | ||||||
|         </div> |  | ||||||
|     </div> |  | ||||||
| 
 |  | ||||||
| </form> |  | ||||||
| {/block} |  | ||||||
| @ -1,5 +1,17 @@ | |||||||
| <?php | <?php | ||||||
| 
 | 
 | ||||||
|  | // +----------------------------------------------------------------------
 | ||||||
|  | // | ThinkAdmin
 | ||||||
|  | // +----------------------------------------------------------------------
 | ||||||
|  | // | 版权所有 2014~2017 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
 | ||||||
|  | // +----------------------------------------------------------------------
 | ||||||
|  | // | 官方网站: http://think.ctolog.com
 | ||||||
|  | // +----------------------------------------------------------------------
 | ||||||
|  | // | 开源协议 ( https://mit-license.org )
 | ||||||
|  | // +----------------------------------------------------------------------
 | ||||||
|  | // | github开源项目:https://github.com/zoujingli/ThinkAdmin
 | ||||||
|  | // +----------------------------------------------------------------------
 | ||||||
|  | 
 | ||||||
| return [ | return [ | ||||||
|     'service_url' => 'http://service.thinkadmin.top', |     'service_url' => 'http://service.thinkadmin.top', | ||||||
| ]; | ]; | ||||||
| @ -1,171 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| // +----------------------------------------------------------------------
 |  | ||||||
| // | ThinkAdmin
 |  | ||||||
| // +----------------------------------------------------------------------
 |  | ||||||
| // | 版权所有 2014~2017 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
 |  | ||||||
| // +----------------------------------------------------------------------
 |  | ||||||
| // | 官方网站: http://think.ctolog.com
 |  | ||||||
| // +----------------------------------------------------------------------
 |  | ||||||
| // | 开源协议 ( http://www.apache.org/licenses/LICENSE-2.0 )
 |  | ||||||
| // +----------------------------------------------------------------------
 |  | ||||||
| // | github开源项目:https://github.com/zoujingli/ThinkAdmin
 |  | ||||||
| // +----------------------------------------------------------------------
 |  | ||||||
| 
 |  | ||||||
| namespace service; |  | ||||||
| 
 |  | ||||||
| use think\Db; |  | ||||||
| use think\Request; |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * 扩展服务 |  | ||||||
|  * Class ExtendService |  | ||||||
|  * @package service |  | ||||||
|  */ |  | ||||||
| class ExtendService |  | ||||||
| { |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * 发送短信验证码 |  | ||||||
|      * @param string $phone 手机号 |  | ||||||
|      * @param string $content 短信内容 |  | ||||||
|      * @param string $productid 短信通道ID |  | ||||||
|      * @return bool |  | ||||||
|      * @throws \think\Exception |  | ||||||
|      * @throws \think\exception\PDOException |  | ||||||
|      */ |  | ||||||
|     public static function sendSms($phone, $content, $productid = '676767') |  | ||||||
|     { |  | ||||||
|         $tkey = date("YmdHis"); |  | ||||||
|         $data = [ |  | ||||||
|             'tkey'      => $tkey, |  | ||||||
|             'mobile'    => $phone, |  | ||||||
|             'content'   => $content, |  | ||||||
|             'username'  => sysconf('sms_username'), |  | ||||||
|             'productid' => $productid, |  | ||||||
|             'password'  => md5(md5(sysconf('sms_password')) . $tkey), |  | ||||||
|         ]; |  | ||||||
|         $result = HttpService::post('http://www.ztsms.cn/sendNSms.do', $data); |  | ||||||
|         list($code, $msg) = explode(',', $result . ','); |  | ||||||
|         $insert = ['phone' => $phone, 'content' => $content, 'result' => $result]; |  | ||||||
|         Db::name('MemberSmsHistory')->insert($insert); |  | ||||||
|         return intval($code) === 1; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * 查询短信余额 |  | ||||||
|      * @return array |  | ||||||
|      * @throws \think\Exception |  | ||||||
|      * @throws \think\exception\PDOException |  | ||||||
|      */ |  | ||||||
|     public static function querySmsBalance() |  | ||||||
|     { |  | ||||||
|         $tkey = date("YmdHis"); |  | ||||||
|         $data = [ |  | ||||||
|             'tkey'     => $tkey, |  | ||||||
|             'username' => sysconf('sms_username'), |  | ||||||
|             'password' => md5(md5(sysconf('sms_password')) . $tkey), |  | ||||||
|         ]; |  | ||||||
|         $result = HttpService::post('http://www.ztsms.cn/balanceN.do', $data); |  | ||||||
|         if ($result > -1) { |  | ||||||
|             return ['code' => 1, 'num' => $result, 'msg' => '获取短信剩余条数成功!']; |  | ||||||
|         } elseif ($result > -2) { |  | ||||||
|             return ['code' => 0, 'num' => '0', 'msg' => '用户名或者密码不正确!']; |  | ||||||
|         } elseif ($result > -3) { |  | ||||||
|             return ['code' => 0, 'num' => '0', 'msg' => 'tkey不正确!']; |  | ||||||
|         } elseif ($result > -4) { |  | ||||||
|             return ['code' => 0, 'num' => '0', 'msg' => '用户不存在或用户停用!']; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * 通用物流单查询 |  | ||||||
|      * @param string $code 快递物流编号 |  | ||||||
|      * @return array |  | ||||||
|      */ |  | ||||||
|     public static function expressByAuto($code) |  | ||||||
|     { |  | ||||||
|         list($result, $client_ip) = [[], Request::instance()->ip()]; |  | ||||||
|         $header = ['Host' => 'www.kuaidi100.com', 'CLIENT-IP' => $client_ip, 'X-FORWARDED-FOR' => $client_ip]; |  | ||||||
|         $autoResult = HttpService::get("http://www.kuaidi100.com/autonumber/autoComNum?text={$code}", [], ['header' => $header, 'timeout' => 30]); |  | ||||||
|         foreach (json_decode($autoResult)->auto as $vo) { |  | ||||||
|             $result[$vo->comCode] = self::express($vo->comCode, $code); |  | ||||||
|         } |  | ||||||
|         return $result; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * 查询物流信息 |  | ||||||
|      * @param string $express_code 快递公司编辑 |  | ||||||
|      * @param string $express_no 快递物流编号 |  | ||||||
|      * @return array |  | ||||||
|      */ |  | ||||||
|     public static function express($express_code, $express_no) |  | ||||||
|     { |  | ||||||
|         list($microtime, $client_ip) = [microtime(true), Request::instance()->ip()]; |  | ||||||
|         $header = ['Host' => 'www.kuaidi100.com', 'CLIENT-IP' => $client_ip, 'X-FORWARDED-FOR' => $client_ip]; |  | ||||||
|         $location = "http://www.kuaidi100.com/query?type={$express_code}&postid={$express_no}&id=1&valicode=&temp={$microtime}"; |  | ||||||
|         return json_decode(HttpService::get($location, [], ['header' => $header, 'timeout' => 30]), true); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * 下载CSV文件 |  | ||||||
|      * @param string $filename 导出文件名 |  | ||||||
|      * @param array $options 数据规则,如:['用户名'=>'username','性别'=>'sex'] |  | ||||||
|      * @param \think\Db\Query $query |  | ||||||
|      * @throws \think\exception\DbException |  | ||||||
|      */ |  | ||||||
|     public static function downloadCsv($filename, $options, $query) |  | ||||||
|     { |  | ||||||
|         self::downloadCsvHeader($filename, array_keys($options)); |  | ||||||
|         $query->chunk(1000, function ($list) use ($options) { |  | ||||||
|             self::downloadCsvBody($list, array_values($options)); |  | ||||||
|         }); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * 写入CSV文件头部 |  | ||||||
|      * @param string $filename 导出文件 |  | ||||||
|      * @param array $headers CSV 头部(一级数组) |  | ||||||
|      */ |  | ||||||
|     public static function downloadCsvHeader($filename, $headers) |  | ||||||
|     { |  | ||||||
|         header('Content-Type: application/octet-stream'); |  | ||||||
|         header("Content-Disposition: attachment; filename=" . iconv('utf-8', 'gbk//TRANSLIT', $filename)); |  | ||||||
|         echo @iconv('utf-8', 'gbk//TRANSLIT', '"' . implode('","', $headers) . "\"\n"); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * 写入CSV文件内容 |  | ||||||
|      * @param array $list 数据列表(二维数组或多维数组) |  | ||||||
|      * @param array $rules 数据规则(一维数组) |  | ||||||
|      */ |  | ||||||
|     public static function downloadCsvBody($list, $rules) |  | ||||||
|     { |  | ||||||
|         foreach ($list as $data) { |  | ||||||
|             $rows = []; |  | ||||||
|             foreach ($rules as $rule) { |  | ||||||
|                 $item = self::parseKeyDot($data, $rule); |  | ||||||
|                 $rows[] = $item === $data ? '' : $item; |  | ||||||
|             } |  | ||||||
|             echo @iconv('utf-8', 'gbk//TRANSLIT', '"' . implode('","', $rows) . "\"\n"); |  | ||||||
|             flush(); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * 根据数组key查询(可带点规则) |  | ||||||
|      * @param array $data 数据 |  | ||||||
|      * @param string $rule 规则,如: order.order_no |  | ||||||
|      * @return mixed |  | ||||||
|      */ |  | ||||||
|     private static function parseKeyDot($data, $rule) |  | ||||||
|     { |  | ||||||
|         list($temp, $attr) = [$data, explode('.', trim($rule, '.'))]; |  | ||||||
|         while ($key = array_shift($attr)) { |  | ||||||
|             $temp = isset($temp[$key]) ? $temp[$key] : $temp; |  | ||||||
|         } |  | ||||||
|         return is_string($temp) ? $temp : ''; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| } |  | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user