common.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. // 接口公共方法
  3. use app\common\model\UserMessage;
  4. use think\Db;
  5. use JPush\Client;
  6. require_once env('root_path').'vendor/jpush/jpush/autoload.php';
  7. function Jpush($user_id = 0,$alert = '',$module='',$type='',$rel_id=''){
  8. $appKey = '02a7faefd91c8a6a446a6a14';
  9. $masterSecret = 'ba2e100db997024d9b6e5d35';
  10. $client = new Client($appKey, $masterSecret,null);
  11. $push_payload = $client->push()
  12. ->setPlatform(array('ios', 'android'))
  13. ->addAlias(strval($user_id))
  14. ->iosNotification($alert, array(
  15. 'badge' => '+1',
  16. 'content-available' => true,
  17. 'mutable-content' => true,
  18. 'category' => 'jiguang',
  19. 'extras' => array(
  20. 'key' => 'value',
  21. 'module' => $module,
  22. 'type' => $type,
  23. 'rel_id' => $rel_id,
  24. ),
  25. ))->androidNotification($alert, array(
  26. 'title' => '消息通知',
  27. // 'builder_id' => 2,
  28. 'extras' => array(
  29. 'module' => $module,
  30. 'type' => $type,
  31. 'rel_id' => $rel_id,
  32. ),
  33. ))->options(array(
  34. 'apns_production' => true,// false 开发环境 ,true 生产环境
  35. ));
  36. try {
  37. $response = $push_payload->send();
  38. return $response;
  39. } catch (\JPush\Exceptions\APIConnectionException $e) {
  40. return $e;
  41. } catch (\JPush\Exceptions\APIRequestException $e) {
  42. return $e;
  43. }
  44. }
  45. function get_order_sn(){
  46. $order_id_main = date('YmdHis') . rand(10000000,99999999);
  47. $order_id_len = strlen($order_id_main);
  48. $order_id_sum = 0;
  49. for($i=0; $i<$order_id_len; $i++){
  50. $order_id_sum += (int)(substr($order_id_main,$i,1));
  51. }
  52. $osn = $order_id_main . str_pad((100 - $order_id_sum % 100) % 100,2,'0',STR_PAD_LEFT);
  53. return $osn;
  54. }
  55. function encrypt_password($password){
  56. return password_hash($password,PASSWORD_DEFAULT);
  57. }
  58. function check_password($password,$hash)
  59. {
  60. return password_verify($password,$hash);
  61. }
  62. // 获取日历 默认最近7天
  63. function get_calendar($day = 7,$type='asc'){
  64. $data = [];
  65. $week_arr = ['日','一','二','三','四','五','六'];
  66. for($i=0;$i<$day;$i++) {
  67. $day_time = date('Y-m-d',strtotime("-$i days"));
  68. $day_title= trim(date('m月d日',strtotime("-$i days")),'0');
  69. $time_int = strtotime($day_time);
  70. $week_day =$week_arr[date('w',strtotime($day_time))];
  71. $data[] = ['day_time' => $day_time,'week_day'=>$week_day,'time_int'=>$time_int,'day_title'=>$day_title];
  72. }
  73. if($type == 'asc') array_multisort(array_column($data,'time_int'),SORT_ASC,$data);
  74. return $data;
  75. }
  76. function jg_push()
  77. {
  78. $user_id = 65 ;
  79. $alert ='aaa';
  80. if(empty($user_id)) return false;
  81. $appKey = '02a7faefd91c8a6a446a6a14';
  82. $masterSecret = 'ba2e100db997024d9b6e5d35';
  83. $client = new Client($appKey, $masterSecret,null);
  84. $push_payload = $client->push()
  85. ->setPlatform(array('ios', 'android'))
  86. ->addAlias(strval($user_id))
  87. ->iosNotification($alert, array(
  88. 'badge' => '+1',
  89. 'content-available' => true,
  90. 'mutable-content' => true,
  91. 'category' => 'jiguang',
  92. 'extras' => array(
  93. 'key' => 'value',
  94. 'jiguang'
  95. ),
  96. ))->androidNotification($alert, array(
  97. 'title' => '消息通知',
  98. // 'builder_id' => 2,
  99. 'extras' => array(
  100. 'key' => 'value',
  101. 'jiguang'
  102. ),
  103. ))->options(array(
  104. 'apns_production' => True,
  105. ));
  106. try {
  107. $response = $push_payload->send();
  108. return $response;
  109. } catch (\JPush\Exceptions\APIConnectionException $e) {
  110. return $e;
  111. } catch (\JPush\Exceptions\APIRequestException $e) {
  112. return $e;
  113. }
  114. }
  115. function numTransform($num)
  116. {
  117. $cal = 10000;
  118. $num = intval($num);
  119. if($num < $cal) return $num;
  120. $cal_num = bcdiv($num,$cal,1);
  121. return $cal_num.'w+';
  122. }