common.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <?php
  2. use think\Db;
  3. /**
  4. * 秒转换为天
  5. */
  6. function get_stay_time($remain_time, $is_hour = 1, $is_minutes = 1)
  7. {
  8. $day = floor($remain_time / (3600*24));
  9. $day = $day > 0 ? $day.'天' : '';
  10. $hour = floor(($remain_time % (3600*24)) / 3600);
  11. $hour = $hour > 0 ? $hour.'小时' : '';
  12. if($is_hour && $is_minutes) {
  13. $minutes = floor((($remain_time % (3600*24)) % 3600) / 60);
  14. $minutes = $minutes > 0 ? $minutes.'分钟' : '';
  15. return $day.$hour.$minutes;
  16. }
  17. if($hour) {
  18. return $day.$hour;
  19. }
  20. return $day;
  21. }
  22. //获取全图片地址 $image_data
  23. function image_path($image_data){
  24. if(empty($image_data)){
  25. return $image_data;
  26. }
  27. if (strpos($image_data,'|')!==false){
  28. $image_res = explode('|',$image_data);
  29. }elseif(strpos($image_data,',')!==false){
  30. $image_res = explode(',',$image_data);
  31. }else{
  32. $image_res = array($image_data);
  33. }
  34. return $image_res;
  35. }
  36. // 密码加密
  37. function encryption_password($password)
  38. {
  39. return md5($password);
  40. }
  41. /**
  42. * @param $id_card
  43. * @return false|string
  44. */
  45. function get_age($id_card){
  46. # 1.从身份证中获取出生日期
  47. $birth_Date = strtotime(substr($id_card, 6, 8));//截取日期并转为时间戳
  48. # 2.格式化[出生日期]
  49. $Year = date('Y', $birth_Date);//yyyy
  50. $Month = date('m', $birth_Date);//mm
  51. $Day = date('d', $birth_Date);//dd
  52. # 3.格式化[当前日期]
  53. $current_Y = date('Y');//yyyy
  54. $current_M = date('m');//mm
  55. $current_D = date('d');//dd
  56. # 4.计算年龄()
  57. $age = $current_Y - $Year;//今年减去生日年
  58. if($Month > $current_M || $Month == $current_M && $Day > $current_D){//深层判断(日)
  59. $age--;//如果出生月大于当前月或出生月等于当前月但出生日大于当前日则减一岁
  60. }
  61. # 返回
  62. return $age;
  63. }
  64. function create_invite_code($user_id){
  65. // 生成12位邀请码
  66. $code_str = '';
  67. $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");
  68. $code_key = array_rand($base_code, 8 - strlen( $this->_user->id));
  69. array_map(function ($val)use (&$code_str,$base_code){
  70. $code_str .=$base_code[$val] ;
  71. },$code_key);
  72. return $code_str;
  73. }
  74. // 获取模板区域
  75. function get_city_area()
  76. {
  77. $field=['id','pid','name'];
  78. $list=Db::table('store_area')->where('pid',0)->field($field)->select();
  79. foreach ($list as $k=>&$v){
  80. $v['children']= Db::table('store_area')->where('pid',$v['id'])->field($field)->select();
  81. }
  82. return $list;
  83. }
  84. function http_curl($url,$type='get',$res='json',$arr=''){
  85. $headers = array();
  86. //根据API的要求,定义相对应的Content-Type
  87. array_push($headers, "Content-Type".":"."application/x-www-form-urlencoded; charset=UTF-8;application/json");
  88. $curl = curl_init();
  89. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $type);
  90. curl_setopt($curl, CURLOPT_URL, $url);
  91. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  92. curl_setopt($curl, CURLOPT_FAILONERROR, false);
  93. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  94. curl_setopt($curl, CURLOPT_HEADER, false);
  95. $output = curl_exec($curl);
  96. curl_close($curl);
  97. if($res=='json'){
  98. if($output === false){
  99. //请求失败,返回错误信息
  100. return curl_error($curl);
  101. }else{
  102. //请求成功,返回信息
  103. return json_decode($output,true);
  104. }
  105. }
  106. }
  107. // 获取物流信息
  108. function get_delivery($send_no = 'JD0053309649641',$express_code=''){
  109. error_reporting(E_ALL || ~E_NOTICE);
  110. $AppKey = 204008273;
  111. $AppSecret ='t9PavvfCeK5v2XidwyK5pWDp8b0hzMq4';
  112. $AppCode ='47f640e3529d43e28365311a530db2b7';//开通服务后 买家中心-查看AppCode
  113. $host = "https://wuliu.market.alicloudapi.com";//api访问链接
  114. $path = "/kdi";//API访问后缀
  115. $method = "GET";
  116. $body ='';
  117. $headers = array();
  118. array_push($headers, "Authorization:APPCODE " . $AppCode);
  119. $querys = "no={$send_no}&type={$express_code}"; //参数写在这里
  120. $url = $host . $path . "?" . $querys;
  121. $curl = curl_init();
  122. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
  123. curl_setopt($curl, CURLOPT_URL, $url);
  124. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  125. curl_setopt($curl, CURLOPT_FAILONERROR, false);
  126. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  127. curl_setopt($curl, CURLOPT_HEADER, true);
  128. if (1 == strpos("$" . $host, "https://")) {
  129. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  130. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  131. }
  132. $out_put = curl_exec($curl);
  133. $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  134. list($header, $body) = explode("\r\n\r\n", $out_put, 2);
  135. if ($httpCode == 200) {
  136. return json_decode($body,true)['result'];
  137. } else {
  138. return [];
  139. }
  140. }
  141. // 元石日志
  142. function crystal_log($user_id,$crystal,$desc,$type,$rel_id=0)
  143. {
  144. $log_data = [
  145. 'user_id' => $user_id,
  146. 'create_at' => date('Y-m-d H:i:s'),
  147. 'crystal' => $crystal,
  148. 'desc' => $desc,
  149. 'type' => $type,
  150. 'rel_id' => $rel_id,
  151. ];
  152. Db::table('crystal_info')->insert($log_data);
  153. }
  154. // 实名认证
  155. function user_certification($id_card,$name){
  156. $host = "http://checkone.market.alicloudapi.com";
  157. $path = "/chinadatapay/1882";
  158. $method = "POST";
  159. $appcode = "30be8bdcc65842919980a8276ffc4995";
  160. $headers = array();
  161. array_push($headers, "Authorization:APPCODE " . $appcode);
  162. //根据API的要求,定义相对应的Content-Type
  163. array_push($headers, "Content-Type".":"."application/x-www-form-urlencoded; charset=UTF-8");
  164. $bodys = "idcard=".$id_card."&name=".$name;
  165. $url = $host . $path;
  166. $curl = curl_init();
  167. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
  168. curl_setopt($curl, CURLOPT_URL, $url);
  169. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  170. curl_setopt($curl, CURLOPT_FAILONERROR, false);
  171. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  172. curl_setopt($curl, CURLOPT_HEADER, false);
  173. if (1 == strpos("$".$host, "https://"))
  174. {
  175. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  176. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  177. }
  178. curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
  179. $res = curl_exec($curl);
  180. if($res){
  181. $res = json_decode($res,true);
  182. if($res['data']['result'] == 1){
  183. return 1;
  184. }else{
  185. return 0;
  186. }
  187. }else{
  188. return 0;
  189. }
  190. }
  191. // 刷新页面
  192. function to_reload()
  193. {
  194. if(input('reloaded') !=1) {
  195. echo "<script>
  196. location.href=location.href+'&reloaded=1';
  197. location.reload();
  198. </script>";
  199. }
  200. }
  201. function shoucang(){
  202. $host = "http://180.76.141.31:8888/cz/call";
  203. $method = "POST";
  204. $headers = array();
  205. array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");
  206. $bodys = array(
  207. 'key' => 'test2',
  208. 'userkey' => '12344',
  209. 'product' => json_encode(array('name'=>'test','count'=>7))
  210. );
  211. $curl = curl_init();
  212. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
  213. curl_setopt($curl, CURLOPT_URL, $host);
  214. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  215. curl_setopt($curl, CURLOPT_FAILONERROR, false);
  216. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  217. curl_setopt($curl, CURLOPT_HEADER, false);
  218. if (1 == strpos("$".$host, "https://"))
  219. {
  220. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  221. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  222. }
  223. curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($bodys));
  224. $res = curl_exec($curl);
  225. var_dump($res);exit();
  226. }