作者 lyh

gx

  1 +<?php
  2 +
  3 +namespace App\Helper;
  4 +
  5 +use GuzzleHttp\Client;
  6 +
  7 +/**
  8 + * @name: ayr_share社交绑定
  9 + */
  10 +class AyrShare
  11 +{
  12 + public $path = 'https://app.ayrshare.com/api';
  13 + //api_key
  14 + public $api_key = 'G8GQW3X-XBTMGXW-QPDDZ9A-WE1Z5SB';
  15 + //系统设置
  16 + public $config = [
  17 +
  18 + ];
  19 + //profile_key
  20 + public $profile_key = "-----BEGIN RSA PRIVATE KEY-----
  21 + MIICWgIBAAKBgGFatMeBeaw7QJrqmylMLZlwuuO0FA/EZg5/g7Rrqu+FgpwvFkJq
  22 + 9twEZJY+aIdDH8/RVrCZQGR/xUxKw9v4ows+sLwi4g41m8KRKDXUcJwQvSlwsHAi
  23 + h9hPGZxDsRK0Nv4pZ7XqGgh0Wb0VypX/+Q1dhX9BnXQmvEKayk8GQWQxAgMBAAEC
  24 + gYAFqOJNnudV7fPpja4LjpQwEW+sATIRYJeWTC9587ByUE6xicM/hTxouhCm82Xc
  25 + Rzi4OjFR/vbRYOQ1dTtBtIi18fdRrseQNyR/N2NZjw1X8n5aZcw5NVaa3d3YTQNa
  26 + uzjnYF5eYSOD4pNKKIDc35VHdmvGCV/JXwQKMTgu1+4AAQJBAL5jjN3kvMKFF8vG
  27 + DyYR8k+wPG9iXAdR0HjVNB3OzxKVW0MTwM32pJBXCmF1MOziL8WC48VHQL48hVRa
  28 + 52xRqAECQQCC53rrrOPhPCLIb6kBfgqnxCojqlUK9paFL7NYTPtLYcOajY6+NiKT
  29 + CG1gaOwZh4r34HF7I59l/Ds98Z4nQDwxAkAC4/oIiGeBQIoK8vfZ6R3XreJNAp5J
  30 + EinrG7mN1kz4iEH5c7xSpDL9agTjU+cpQYneIs2Yeit2d+7CSBsJXvgBAkBDFsfU
  31 + yYLxCJT7DN8dOK/VU6AVL1Luj3qNP+k2tB2GgNBzAWHK8ou9t2/3HU8DtofuikUe
  32 + yx8Cccca9B4OF8nBAkAgIUZKGmVNFcGnFFo55vSJInNXFo4HCJ2o4DunBORVtQ/j
  33 + zFePUMXy1bFghAfzNKlrc5XgH4ixeeMh3cDtU97K
  34 + -----END RSA PRIVATE KEY-----";
  35 + //设置请求头
  36 + public $headers = [
  37 + 'Authorization' => 'Bearer ',
  38 + 'Content-Type' => 'application/json',
  39 +// 'Accept-Encoding' => 'deflate, gzip',
  40 + ];
  41 +
  42 + /**
  43 + * @name :参数构建
  44 + */
  45 + public function __construct()
  46 + {
  47 + $this->headers['Authorization'] = $this->headers['Authorization'].$this->api_key;
  48 + }
  49 +
  50 + /**
  51 + * @name :获取过去30天发布的历史记录(1-30)
  52 + * @author :lyh
  53 + * @method :get
  54 + * @time :2023/5/5 10:00
  55 + */
  56 + public function get_analytics_links($to_day){
  57 + $last_days = (string)$to_day;
  58 + $url = $this->path.'/analytics/links?lastDays='.$last_days;
  59 + return $this->http_click('get',$url);
  60 + }
  61 +
  62 + /**
  63 + * @name :(通过 Ayrshare 获取给定帖子的实时分析,例如点赞、印象、转推等)post_analytics
  64 + * @author :lyh
  65 + * @method :post
  66 + * @time :2023/5/5 11:56
  67 + */
  68 + public function post_analytics($id){
  69 + $param = [
  70 + 'id'=>$id,
  71 + 'platforms' => ['facebook', 'instagram', 'twitter', 'linkedin', 'pinterest', 'youtube', 'tiktok'],
  72 + ];
  73 + $url = $this->path.'/api/analytics/post';
  74 + return $this->http_click('post', $url, $param);
  75 + }
  76 + /**
  77 + * @name :(获取特定用户个人资料)analytics_post
  78 + * @author :lyh
  79 + * @method :post
  80 + * @time :2023/5/5 10:43
  81 + */
  82 + public function post_analytics_social(){
  83 + $post_data = [
  84 + 'platforms' => ['facebook', 'instagram', 'twitter', 'linkedin', 'pinterest', 'youtube', 'tiktok'],
  85 + ];
  86 + $url = $this->path.'/api/analytics/social';
  87 + return $this->http_click('post',$url,$post_data);
  88 + }
  89 +
  90 + /**
  91 + * @name :(设置自动计划)post_schedule_set
  92 + * @author :lyh
  93 + * @method :post
  94 + * @time :2023/5/5 13:58
  95 + */
  96 + public function post_schedule_set($data){
  97 + $param = [
  98 + 'schedule'=>["13:05Z", "20:14Z"],
  99 + 'title'=>$data['title'],
  100 + ];
  101 + $url = $this->path.'/api/auto-schedule/set';
  102 + return $this->http_click('post',$url,$param);
  103 + }
  104 +
  105 + /**
  106 + * @name :(删除自动计划)delete_schedule
  107 + * @author :lyh
  108 + * @method :post
  109 + * @time :2023/5/5 14:04
  110 + */
  111 + public function delete_schedule($data){
  112 + $param = [
  113 + 'title'=>$data['title'],
  114 + ];
  115 + $url = $this->path.'/api/auto-schedule/delete';
  116 + return $this->http_click('delete',$url,$param);
  117 + }
  118 +
  119 + /**
  120 + * @name :(列出自动计划)get_schedule_list
  121 + * @author :lyh
  122 + * @method :post
  123 + * @time :2023/5/5 14:08
  124 + */
  125 + public function get_schedule_list(){
  126 + $url = $this->path.'/api/auto-schedule/list';
  127 + return $this->http_click('get',$url);
  128 + }
  129 +
  130 + /**
  131 + * @name :(发布到用户个人资料)post_user
  132 + * @author :lyh
  133 + * @method :post
  134 + * @time :2023/5/5 15:00
  135 + */
  136 + public function post_user($data){
  137 + $param = [
  138 + 'post'=>$data['post'],
  139 + 'platforms'=>$data['platforms'],
  140 + 'profileKey'=>$this->profile_key,
  141 + ''=>
  142 + ];
  143 + }
  144 +
  145 + /**
  146 + * @name :(获取有关用户社交资料的分析和人口统计,例如印象,视图和关注着)post_social
  147 + * @author :lyh
  148 + * @method :post
  149 + * @time :2023/5/5 10:37
  150 + */
  151 + public function api_user(){
  152 + $post_data = [
  153 + 'platforms' => ['facebook', 'instagram', 'twitter', 'linkedin', 'pinterest', 'youtube', 'tiktok'],
  154 + ];
  155 + $url = $this->path.'/api/user';
  156 + return $this->http_click('post',$url,$post_data);
  157 + }
  158 +
  159 +
  160 + /**
  161 + * 发送http post,get,put,delete请求
  162 + * @param type $url
  163 + * @param type $post_data
  164 + */
  165 + function http_click($method = 'post',$url, $param = [],$header = [])
  166 + {
  167 + if(!empty($param)){
  168 + $post_data['json'] = $param;
  169 + }
  170 + $post_data['headers'] = !empty($header) ? $header : $this->headers;
  171 + $client = new Client();
  172 + try {
  173 + $res = $client->request($method, $url, $post_data)->getBody()->getContents();
  174 + return $res;
  175 + } catch (\Exception $e) {
  176 + return json_encode(["status"=>"fail","message"=>$e->getMessage()]);
  177 + }
  178 + }
  179 +}
@@ -7,6 +7,9 @@ use App\Models\User\UserLog as UserLogModel; @@ -7,6 +7,9 @@ use App\Models\User\UserLog as UserLogModel;
7 use App\Models\User\UserLogin as UserLoginModel; 7 use App\Models\User\UserLogin as UserLoginModel;
8 use Illuminate\Support\Facades\Cache; 8 use Illuminate\Support\Facades\Cache;
9 9
  10 +/**
  11 + * @name:
  12 + */
10 class Common 13 class Common
11 { 14 {
12 /** 15 /**
@@ -4,6 +4,9 @@ namespace App\Helper; @@ -4,6 +4,9 @@ namespace App\Helper;
4 4
5 use App\Models\WebSetting\WebSettingCountry; 5 use App\Models\WebSetting\WebSettingCountry;
6 6
  7 +/**
  8 + * @name:多语言国家设置
  9 + */
7 class Country 10 class Country
8 { 11 {
9 public $tls_list = [ 12 public $tls_list = [
@@ -681,6 +684,6 @@ class Country @@ -681,6 +684,6 @@ class Country
681 } 684 }
682 $webCountry = new WebSettingCountry(); 685 $webCountry = new WebSettingCountry();
683 $webCountry->insert($data); 686 $webCountry->insert($data);
684 - return; 687 + return true;
685 } 688 }
686 } 689 }
@@ -37,12 +37,14 @@ if(!function_exists('http_post')){ @@ -37,12 +37,14 @@ if(!function_exists('http_post')){
37 * @param type $url 37 * @param type $url
38 * @param type $post_data 38 * @param type $post_data
39 */ 39 */
40 - function http_post($url, $post_data) 40 + function http_post($url, $post_data,$header = [])
41 { 41 {
42 - $header = array(  
43 - "Accept: application/json",  
44 - "Content-Type:application/json;charset=utf-8",  
45 - ); 42 + if(empty($header)){
  43 + $header = array(
  44 + "Accept: application/json",
  45 + "Content-Type:application/json;charset=utf-8",
  46 + );
  47 + }
46 $ch = curl_init(); 48 $ch = curl_init();
47 curl_setopt($ch, CURLOPT_URL, $url); 49 curl_setopt($ch, CURLOPT_URL, $url);
48 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 50 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
@@ -69,10 +71,12 @@ if(!function_exists('http_get')){ @@ -69,10 +71,12 @@ if(!function_exists('http_get')){
69 * @param type $url 71 * @param type $url
70 * @return type 72 * @return type
71 */ 73 */
72 - function http_get($url) 74 + function http_get($url,$header = [])
73 { 75 {
74 - $header[] = "content-type: application/x-www-form-urlencoded; 76 + if(empty($header)){
  77 + $header[] = "content-type: application/json;
75 charset = UTF-8"; 78 charset = UTF-8";
  79 + }
76 $ch1 = curl_init(); 80 $ch1 = curl_init();
77 $timeout = 5; 81 $timeout = 5;
78 curl_setopt($ch1, CURLOPT_URL, $url); 82 curl_setopt($ch1, CURLOPT_URL, $url);
@@ -6,8 +6,6 @@ use App\Enums\Common\Code; @@ -6,8 +6,6 @@ use App\Enums\Common\Code;
6 use App\Models\Image as ImageModel; 6 use App\Models\Image as ImageModel;
7 use Illuminate\Http\Exceptions\HttpResponseException; 7 use Illuminate\Http\Exceptions\HttpResponseException;
8 use Illuminate\Http\JsonResponse; 8 use Illuminate\Http\JsonResponse;
9 -use Illuminate\Http\Request;  
10 -use Illuminate\Support\Facades\DB;  
11 use Illuminate\Support\Facades\Storage; 9 use Illuminate\Support\Facades\Storage;
12 use Intervention\Image\Facades\Image; 10 use Intervention\Image\Facades\Image;
13 11
@@ -32,9 +30,9 @@ class ImageController @@ -32,9 +30,9 @@ class ImageController
32 30
33 public $request = ''; 31 public $request = '';
34 32
35 - public function __construct(Request $request) 33 + public function __construct()
36 { 34 {
37 - $this->request = $request; 35 + $this->request = request();
38 $this->config = config('filesystems.disks.upload'); 36 $this->config = config('filesystems.disks.upload');
39 $this->path = $this->config['root']; 37 $this->path = $this->config['root'];
40 } 38 }
@@ -60,19 +60,19 @@ class NewsLogic extends BaseLogic @@ -60,19 +60,19 @@ class NewsLogic extends BaseLogic
60 $this->param['project_id'] = $this->user['project_id']; 60 $this->param['project_id'] = $this->user['project_id'];
61 $this->param['created_at'] = date('Y-m-d H:i:s',time()); 61 $this->param['created_at'] = date('Y-m-d H:i:s',time());
62 $this->param['updated_at'] = date('Y-m-d H:i:s',time()); 62 $this->param['updated_at'] = date('Y-m-d H:i:s',time());
63 - DB::beginTransaction();  
64 - try { 63 +// DB::beginTransaction();
  64 +// try {
65 if(isset($this->param['image'])){ 65 if(isset($this->param['image'])){
66 $data = $this->upload(); 66 $data = $this->upload();
67 $this->param['image'] = $data; 67 $this->param['image'] = $data;
68 } 68 }
69 $rs = $this->model->insertGetId($this->param); 69 $rs = $this->model->insertGetId($this->param);
70 RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $rs, $this->user['project_id']); 70 RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $rs, $this->user['project_id']);
71 - DB::commit();  
72 - }catch (\Exception $e){  
73 - DB::rollBack();  
74 - $this->fail('添加失败');  
75 - } 71 +// DB::commit();
  72 +// }catch (\Exception $e){
  73 +// DB::rollBack();
  74 +// $this->fail('添加失败');
  75 +// }
76 return $this->success(); 76 return $this->success();
77 } 77 }
78 78
@@ -25,7 +25,7 @@ class NewsRequest extends FormRequest @@ -25,7 +25,7 @@ class NewsRequest extends FormRequest
25 { 25 {
26 return [ 26 return [
27 'name'=>'required|max:100', 27 'name'=>'required|max:100',
28 - 'remark'=>'required|max:100', 28 + 'remark'=>'required|max:255',
29 'text'=>'required|min:10', 29 'text'=>'required|min:10',
30 'category_id'=>'required', 30 'category_id'=>'required',
31 ]; 31 ];