SendController.php
17.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/9/4
* Time: 10:53
*/
namespace api\index\controller;
use cmf\controller\RestBaseController;
use think\Db;
use think\Validate;
/**
* @title 发布信息
* @description
*/
class SendController extends RestBaseController
{
/**
* @title 我要提供
* @description 我要提供
* @author GuoSheng
* @url /index/Send/index
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:job_title type:string require:1 desc:信息标题
* @param name:end_time type:string require:0 desc:有效日期
* @param name:linkman type:string require:1 desc:联系人
* @param name:linkman_tel type:string require:1 desc:手机号码
* @param name:city type:string require:1 desc: 城市(最多添加五个)
* @param name:company_name type:string require:1 desc:公司名称
* @param name:needpeople type:int require:1 desc:需求人数
* @param name:content type:text require:1 desc:项目详情
* @param name:status type:int require:1 desc:保存为0 发布为1
* @param name:image type:string require:0 desc:项目详情图片
*/
public function index()
{
$user_id = $this->getUserId();
$param = $this->request->param();
$param['user_id'] = $user_id;
$param['create_time'] = time();
$param['job_type'] = 1;
if(empty($param['end_time'])){
$param['end_time'] = $param['create_time']+7*24*60*60;
}else{
$end_time = strtotime($param['end_time']);
if($end_time<$param['create_time']+86400){
$this->error('请选择合理日期');
}else{
$param['end_time'] = strtotime($param['end_time']);
}
}
if($param['status'] == 0){
$data = Db::name('job')
->insert($param);
if(empty($data)){
$this->error(['code'=>40006,'msg'=>'sql执行失败']);
}
$this->success('SUCCESS');
}else{
$validate = new Validate([
'job_title' => 'require',
'linkman' => 'require',
'needpeople'=>'require',
'city'=>'require',
'linkman_tel'=>'require|number|max:11',
'company_name'=>'require',
'content'=>'require',
]);
if (!$validate->check($param)) {
$this->error(['code'=>40005,'msg'=>$validate->getError()]);
}
$this->secCheck($param['job_title'],1);
$this->secCheck($param['company_name'],1);
$this->secCheck($param['content'],1);
if(!empty($param['image'])){
$this->secCheck($param['image'],2);
}
$data = Db::name('job')
->insert($param);
if(empty($data)){
$this->error(['code'=>40006,'msg'=>'sql执行失败']);
}
$this->success('SUCCESS');
}
}
/**
* @title 二级城市
* @description
* @author GuoSheng
* @url /index/Send/city
* @method GET
*
* @return id:城市ID
* @return name:城市名称
*
*/
public function city()
{
$data = Db::name('area')
->where('level',1)
->field('id,name,sign_id')
->select()
->toArray();
foreach ($data as $k=>$v){
$data[$k]['child'] = Db::name('area')
->where('pid',$v['sign_id'])
->where('level',2)
->field('id,name')
->select()
->toArray();
}
$this->success('SUCCESS',$data);
}
/**
* @title 我有需求
* @description 我有需求
* @author GuoSheng
* @url /index/Send/demand
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:job_title type:string require:1 desc:信息标题
* @param name:end_time type:string require:0 desc:有效日期
* @param name:linkman type:string require:1 desc:联系人
* @param name:linkman_tel type:string require:1 desc:手机号码
* @param name:workplace type:string require:1 desc:工作地点
* @param name:needpeople type:int require:1 desc:需求人数
* @param name:sex type:int require:1 desc:性别 (0女 1男 2不限 )
* @param name:min_age type:int require:0 desc:年龄(最小年龄)
* @param name:max_age type:int require:0 desc:年龄(最大年龄)
* @param name:education type:string require:1 desc:学历
* @param name:company_name type:string require:1 desc:公司名称不能为空
* @param name:empoying type:string require:1 desc:用工单位
* @param name:content type:text require:1 desc:项目详情
* @param name:status type:int require:1 desc:保存为0 发布为1
* @param name:image type:string require:0 desc:项目详情图片
* @param name:city name:string require:1 desc:发布城市
*
*/
public function demand()
{
$user_id = $this->getUserId();
$param = $this->request->param();
$param['user_id'] = $user_id;
$param['create_time'] = time();
$param['job_type'] = 2;
if(empty($param['end_time'])){
$param['end_time'] = $param['create_time']+7*24*60*60;
}else{
$end_time = strtotime($param['end_time']);
if($end_time<$param['create_time']+86400){
$this->error('请选择合理日期');
}else{
$param['end_time'] = strtotime($param['end_time']);
}
}
if(empty($param['min_age'])){
$param['min_age'] = 18;
}
if(empty($param['max_age'])){
$param['max_age'] = 45;
}
if($param['status'] == 0) {
$data = Db::name('job')
->insert($param);
if (empty($data)) {
$this->error(['code' => 40006, 'msg' => 'sql执行失败']);
}
$this->success('SUCCESS');
}else{
$validate = new Validate([
'job_title' => 'require',
'city'=>'require',
'linkman' => 'require',
'workplace'=>'require',
'needpeople' =>'require|number',
'sex'=>'require|number',
'education'=>'require',
'company_name'=>'require',
'empoying'=>'require',
'content'=>'require',
'linkman_tel'=>'require|number|max:11',
]);
if (!$validate->check($param)) {
$this->error(['code'=>40005,'msg'=>$validate->getError()]);
}
$this->secCheck($param['job_title'],1);
$this->secCheck($param['workplace'],1);
$this->secCheck($param['company_name'],1);
$this->secCheck($param['empoying'],1);
$this->secCheck($param['content'],1);
if(!empty($param['image'])){
$this->secCheck($param['image'],2);
}
$data = Db::name('job')
->insert($param);
if(empty($data)){
$this->error(['code'=>40006,'msg'=>'sql执行失败']);
}
$this->success('SUCCESS');
}
}
/**
* @title 同城活动
* @description 同城活动
* @author GuoSheng
* @url /index/Send/active
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:job_title type:string require:1 desc:信息标题
* @param name:end_time type:string require:0 desc:有效日期
* @param name:linkman type:string require:1 desc:联系人
* @param name:linkman_tel type:string require:1 desc:手机号码
* @param name:needpeople type:int require:1 desc:需求人数
* @param name:payroll type:int require:0 desc:费用
* @param name:city type:string require:1 desc: 城市(此处只能添加一个)
* @param name:adress type:string require:1 desc:详细地址
* @param name:company_name type:string require:1 desc:公司名称不能为空
* @param name:content type:text require:1 desc:项目详情
* @param name:status type:int require:1 desc:保存为0 发布为1
* @param name:image type:string require:0 desc:项目详情图片
*
*/
public function active()
{
$user_id = $this->getUserId();
$param = $this->request->param();
$param['user_id'] = $user_id;
$param['create_time'] = time();
$param['job_type'] = 3;
if(empty($param['end_time'])){
$param['end_time'] = $param['create_time']+7*24*60*60;
}else{
$end_time = strtotime($param['end_time']);
if($end_time<$param['create_time']+86400){
$this->error('请选择合理日期');
}else{
$param['end_time'] = strtotime($param['end_time']);
}
}
if($param['status'] == 0) {
$data = Db::name('job')
->insert($param);
if (empty($data)) {
$this->error(['code' => 40006, 'msg' => 'sql执行失败']);
}
$this->success('SUCCESS');
}else{
$validate = new Validate([
'job_title' => 'require',
'linkman' => 'require',
'linkman_tel'=>'require|number|max:11',
'needpeople' =>'require|number',
'city'=>'require',
'adress'=>'require',
'company_name'=>'require',
'content'=>'require',
]);
if (!$validate->check($param)) {
$this->error(['code'=>40005,'msg'=>$validate->getError()]);
}
$this->secCheck($param['job_title'],1);
$this->secCheck($param['company_name'],1);
$this->secCheck($param['content'],1);
if(!empty($param['image'])){
$this->secCheck($param['image'],2);
}
$data = Db::name('job')
->insert($param);
if(empty($data)){
$this->error(['code'=>40006,'msg'=>'sql执行失败']);
}
$this->success('SUCCESS');
}
}
/**
* @title 招商加盟
* @description 招商加盟
* @author GuoSheng
* @url /index/Send/attract
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:job_title type:string require:1 desc:信息标题
* @param name:end_time type:string require:0 desc:有效日期
* @param name:linkman type:string require:1 desc:联系人
* @param name:linkman_tel type:string require:1 desc:手机号码
* @param name:company_name type:string require:1 desc:公司名称不能为空
* @param name:adress type:string require:1 desc:地址
* @param name:content type:text require:1 desc:项目详情
* @param name:status type:int require:1 desc:保存为0 发布为1
* @param name:image type:string require:0 desc:项目详情图片
* @param name:city type:string require:1 desc:发布城市
*
*/
public function attract()
{
$user_id = $this->getUserId();
$param = $this->request->param();
$param['user_id'] = $user_id;
$param['create_time'] = time();
$param['job_type'] = 4;
if(empty($param['end_time'])){
$param['end_time'] = $param['create_time']+7*24*60*60;
}else{
$end_time = strtotime($param['end_time']);
if($end_time<$param['create_time']+86400){
$this->error('请选择合理日期');
}else{
$param['end_time'] = strtotime($param['end_time']);
}
}
if($param['status'] == 0) {
$data = Db::name('job')
->insert($param);
if (empty($data)) {
$this->error(['code' => 40006, 'msg' => 'sql执行失败']);
}
$this->success('SUCCESS');
}else{
$validate = new Validate([
'job_title' => 'require',
'city'=>'require',
'linkman' => 'require',
'adress'=>'require',
'linkman_tel'=>'require|number|max:11',
'company_name'=>'require',
'content'=>'require',
]);
if (!$validate->check($param)) {
$this->error(['code'=>40005,'msg'=>$validate->getError()]);
}
$this->secCheck($param['job_title'],1);
$this->secCheck($param['company_name'],1);
$this->secCheck($param['adress'],1);
$this->secCheck($param['content'],1);
if(!empty($param['image'])){
$this->secCheck($param['image'],2);
}
$data = Db::name('job')
->insert($param);
if(empty($data)){
$this->error(['code'=>40006,'msg'=>'sql执行失败']);
}
$this->success('SUCCESS');
}
}
public function get_access_token()
{
$app_id = config('app_id');
$app_secret = config('app_secret');
$url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$app_id.'&secret='.$app_secret;
$res = $this->http_get($url);
$json_arr = json_decode($res,true);
$token = $json_arr['access_token'];
return $token;
}
//curl get请求
public function http_get($url){
$curl = curl_init();//启动一个CURL会话
curl_setopt($curl, CURLOPT_URL,$url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环
curl_setopt($curl, CURLOPT_HEADER, false);//不开启header
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // 获取的信息以文件流的形式返回
$result = curl_exec($curl); //执行操作
curl_close($curl);
return $result;
}
/**
* 小程序内容安全审核
* @param $content 审核内容
* @param $type 类型(1,文本;2,图片;3,音频)
*/
public function secCheck($content,$type = 1) {
// if(!$type) {
// return true;
// }
$access_token = $this->get_access_token();
$basic_url = 'https://api.weixin.qq.com/wxa';
if($type == 1) {
$url = $basic_url.'/msg_sec_check?access_token='.$access_token;
if(is_array($content)) {
foreach ($content as $v) {
$this->setUrl($url,['content'=>$v]);
}
} else {
$this->setUrl($url,['content'=>$content]);
}
}
if($type == 2) {
$url = $basic_url.'/media_check_async?access_token='.$access_token;
if(is_array($content)) {
foreach ($content as $v) {
$this->setUrl($url,['media_url'=>$v,'media_type'=>2],'图片');
}
} else {
$this->setUrl($url,['media_url'=>$content,'media_type'=>2],'图片');
}
}
if($type == 3) {
$url = $basic_url.'/media_check_async?access_token='.$access_token;
if(is_array($content)) {
foreach ($content as $v) {
$this->setUrl($url,['media_url'=>$v,'media_type'=>1],'语音');
}
} else {
$this->setUrl($url,['media_url'=>$content,'media_type'=>1],'语音');
}
}
}
/**
* 调用接口审核
* @param $url 跳转地址
* @param $post 审核内容
* @param $type_name
* @param $image
*/
private function setUrl($url,$post,$type_name = '文本') {
$result = $this->curls($url,json_encode($post,JSON_UNESCAPED_UNICODE));
$return_data = json_decode($result,true);
if($return_data['errcode'] != 0) {
$this->error($type_name.'内容含有违法违规内容');
}
}
// curl方法
function curls($url, $post = null, $header = null) {
// 初始化
$curl = curl_init();
// 设置抓取的url
curl_setopt($curl, CURLOPT_URL, $url);
if($header) {
// 请求头
curl_setopt($curl,CURLOPT_HTTPHEADER,$header);
}
// 设置头文件的信息作为数据流输出
curl_setopt($curl, CURLOPT_TIMEOUT, 500);
curl_setopt($curl, CURLINFO_HEADER_OUT, true);
// 设置获取的信息以文件流的形式返回,而不是直接输出。
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
if($post) {
curl_setopt($curl, CURLOPT_POST, 1);
//把POST的变量加上
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
}
// 执行命令
$data = curl_exec($curl);
if (curl_errno($curl)) {
$data = curl_error($curl);
}
return $data;
}
}