123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- <?php
- use think\Db;
- /**
- * 秒转换为天
- */
- function get_stay_time($remain_time, $is_hour = 1, $is_minutes = 1)
- {
- $day = floor($remain_time / (3600*24));
- $day = $day > 0 ? $day.'天' : '';
- $hour = floor(($remain_time % (3600*24)) / 3600);
- $hour = $hour > 0 ? $hour.'小时' : '';
- if($is_hour && $is_minutes) {
- $minutes = floor((($remain_time % (3600*24)) % 3600) / 60);
- $minutes = $minutes > 0 ? $minutes.'分钟' : '';
- return $day.$hour.$minutes;
- }
- if($hour) {
- return $day.$hour;
- }
- return $day;
- }
- //获取全图片地址 $image_data
- function image_path($image_data){
- if(empty($image_data)){
- return $image_data;
- }
- if (strpos($image_data,'|')!==false){
- $image_res = explode('|',$image_data);
- }elseif(strpos($image_data,',')!==false){
- $image_res = explode(',',$image_data);
- }else{
- $image_res = array($image_data);
- }
- return $image_res;
- }
- // 密码加密
- function encryption_password($password)
- {
- return md5($password);
- }
- /**
- * @param $id_card
- * @return false|string
- */
- function get_age($id_card){
- # 1.从身份证中获取出生日期
- $birth_Date = strtotime(substr($id_card, 6, 8));//截取日期并转为时间戳
- # 2.格式化[出生日期]
- $Year = date('Y', $birth_Date);//yyyy
- $Month = date('m', $birth_Date);//mm
- $Day = date('d', $birth_Date);//dd
- # 3.格式化[当前日期]
- $current_Y = date('Y');//yyyy
- $current_M = date('m');//mm
- $current_D = date('d');//dd
- # 4.计算年龄()
- $age = $current_Y - $Year;//今年减去生日年
- if($Month > $current_M || $Month == $current_M && $Day > $current_D){//深层判断(日)
- $age--;//如果出生月大于当前月或出生月等于当前月但出生日大于当前日则减一岁
- }
- # 返回
- return $age;
- }
- function create_invite_code($user_id){
- // 生成12位邀请码
- $code_str = '';
- $base_code = explode(',',"A,B,C,D,E,F,G,H,J,K,L,M,N,P,Q,R,S,T,U,V,W,X,Y,Z");
- $code_key = array_rand($base_code, 8 - strlen( $this->_user->id));
- array_map(function ($val)use (&$code_str,$base_code){
- $code_str .=$base_code[$val] ;
- },$code_key);
- return $code_str;
- }
- // 获取模板区域
- function get_city_area()
- {
- $field=['id','pid','name'];
- $list=Db::table('store_area')->where('pid',0)->field($field)->select();
- foreach ($list as $k=>&$v){
- $v['children']= Db::table('store_area')->where('pid',$v['id'])->field($field)->select();
- }
- return $list;
- }
- function http_curl($url,$type='get',$res='json',$arr=''){
- $headers = array();
- //根据API的要求,定义相对应的Content-Type
- array_push($headers, "Content-Type".":"."application/x-www-form-urlencoded; charset=UTF-8;application/json");
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $type);
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
- curl_setopt($curl, CURLOPT_FAILONERROR, false);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_HEADER, false);
- $output = curl_exec($curl);
- curl_close($curl);
- if($res=='json'){
- if($output === false){
- //请求失败,返回错误信息
- return curl_error($curl);
- }else{
- //请求成功,返回信息
- return json_decode($output,true);
- }
- }
- }
- // 获取物流信息
- function get_delivery($send_no = 'JD0053309649641',$express_code=''){
- error_reporting(E_ALL || ~E_NOTICE);
- $AppKey = 204008273;
- $AppSecret ='t9PavvfCeK5v2XidwyK5pWDp8b0hzMq4';
- $AppCode ='47f640e3529d43e28365311a530db2b7';//开通服务后 买家中心-查看AppCode
- $host = "https://wuliu.market.alicloudapi.com";//api访问链接
- $path = "/kdi";//API访问后缀
- $method = "GET";
- $body ='';
- $headers = array();
- array_push($headers, "Authorization:APPCODE " . $AppCode);
- $querys = "no={$send_no}&type={$express_code}"; //参数写在这里
- $url = $host . $path . "?" . $querys;
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
- curl_setopt($curl, CURLOPT_FAILONERROR, false);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_HEADER, true);
- if (1 == strpos("$" . $host, "https://")) {
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- }
- $out_put = curl_exec($curl);
- $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
- list($header, $body) = explode("\r\n\r\n", $out_put, 2);
- if ($httpCode == 200) {
- return json_decode($body,true)['result'];
- } else {
- return [];
- }
- }
- // 元石日志
- function crystal_log($user_id,$crystal,$desc,$type,$rel_id=0)
- {
- $log_data = [
- 'user_id' => $user_id,
- 'create_at' => date('Y-m-d H:i:s'),
- 'crystal' => $crystal,
- 'desc' => $desc,
- 'type' => $type,
- 'rel_id' => $rel_id,
- ];
- Db::table('crystal_info')->insert($log_data);
- }
- // 实名认证
- function user_certification($id_card,$name){
- $host = "http://checkone.market.alicloudapi.com";
- $path = "/chinadatapay/1882";
- $method = "POST";
- $appcode = "30be8bdcc65842919980a8276ffc4995";
- $headers = array();
- array_push($headers, "Authorization:APPCODE " . $appcode);
- //根据API的要求,定义相对应的Content-Type
- array_push($headers, "Content-Type".":"."application/x-www-form-urlencoded; charset=UTF-8");
- $bodys = "idcard=".$id_card."&name=".$name;
- $url = $host . $path;
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
- curl_setopt($curl, CURLOPT_FAILONERROR, false);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_HEADER, false);
- if (1 == strpos("$".$host, "https://"))
- {
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- }
- curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
- $res = curl_exec($curl);
- if($res){
- $res = json_decode($res,true);
- if($res['data']['result'] == 1){
- return 1;
- }else{
- return 0;
- }
- }else{
- return 0;
- }
- }
- // 刷新页面
- function to_reload()
- {
- if(input('reloaded') !=1) {
- echo "<script>
- location.href=location.href+'&reloaded=1';
- location.reload();
- </script>";
- }
- }
- function shoucang(){
- $host = "http://180.76.141.31:8888/cz/call";
- $method = "POST";
- $headers = array();
- array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");
- $bodys = array(
- 'key' => 'test2',
- 'userkey' => '12344',
- 'product' => json_encode(array('name'=>'test','count'=>7))
- );
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
- curl_setopt($curl, CURLOPT_URL, $host);
- curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
- curl_setopt($curl, CURLOPT_FAILONERROR, false);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_HEADER, false);
- if (1 == strpos("$".$host, "https://"))
- {
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- }
- curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($bodys));
- $res = curl_exec($curl);
- var_dump($res);exit();
- }
|