You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
3.2 KiB

<?php
namespace App\Repositories;
use App\Models\AppointmentConfig;
use App\Models\Course;
use App\Models\ThirdAppointmentLog;
use App\Models\User;
/**
* 元禾控股
*/
class YuanheRepository
{
public $baseUrl;
public $customerId;
public $authKey;
public function __construct()
{
$this->baseUrl = env('YUANHE_BASE_URL');
$this->customerId = env('YUANHE_CUSTOMERID');
$this->authKey = env('YUANHE_AUTHKEY');
}
public function getHeader()
{
$timestamp = time() * 1000;
$token = $this->customerId . $timestamp . $this->authKey;
$token = md5($token);
$token = strtoupper($token);
$header[] = 'Content-Type: application/json';
$header[] = "customerId: {$this->customerId}";
$header[] = "timestamp: {$timestamp}";
$header[] = "token: {$token}";
return $header;
}
/**
* 公司查询
*/
public function companyInfo($params)
{
$params = json_encode($params);
$url = $this->baseUrl . '/master-service/openapi/businessCollege/enterprise/info';
$header = $this->getHeader();
try {
$result = httpCurl($url, 'POST', $params, $header);
$result = json_decode($result, true);
if ($result['code'] == 200) {
return $result['data'];
} else {
return false;
}
} catch (\Exception $e) {
return false;
}
}
/**
* 公司模糊查询
*/
public function search($params)
{
$url = $this->baseUrl . '/master-service/openapi/businessCollege/enterprise/search';
$header = $this->getHeader();
try {
$result = httpCurl($url, 'GET', $params, $header);
$result = json_decode($result, true);
if ($result['code'] == 200) {
return $result['data'];
} else {
return false;
}
} catch (\Exception $e) {
return false;
}
}
/**
* 数据推送
*/
public function pushCourses(Course $course, User $user,&$out)
{
if (empty($user->company)) {
return false;
}
$params = [
'classTeacher' => $course->teacher->name??'',
'courseName' => $course->name,
'description' => $user->company->businessScope??'',
'enterpriseName' => $user->company->company_name,
'creditCode' => $user->company->credit_code,
'groupId' => '1030004',
'openTime' => $course->start_date
];
$params = json_encode($params, JSON_UNESCAPED_UNICODE);
$url = $this->baseUrl . '/master-service/openapi/businessCollege/shareInfo/push';
$header = $this->getHeader();
try {
$result = httpCurl($url, 'POST', $params, $header);
$result = json_decode($result, true);
if ($result['code'] == 200) {
return true;
} else {
$out = $result['msg'];
return false;
}
} catch (\Exception $e) {
$out = $e->getMessage();
return false;
}
}
}