391 lines
13 KiB
PHP
391 lines
13 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
use App\Contracts\ActivityContract;
|
|
use App\Models\Paas;
|
|
use App\Models\PaasActivity;
|
|
use App\Models\Activity;
|
|
use App\Models\ActivityMember;
|
|
use App\Models\Server\EvaluateList;
|
|
use App\Models\User;
|
|
use App\Models\PayOrder;
|
|
use App\Models\Order;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Log;
|
|
use simplehtmldom\HtmlDocument;
|
|
|
|
class EvaluateService
|
|
{
|
|
const IS_TEST = false;
|
|
private static $key = self::IS_TEST?'59854922194C4A39BC3582B630C88D00':'FB35867DA11448F5BFCAA14554483C74';
|
|
private static $url = self::IS_TEST?'https://testopenapi.ydl.com':'https://openapi.ydl.com';
|
|
|
|
private static function curl($url, $method, $headers, $data = null)
|
|
{
|
|
$curl = curl_init();
|
|
$host = self::$url;
|
|
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
|
|
if ($method == 'POST')
|
|
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
|
|
curl_setopt($curl, CURLOPT_URL, $url);
|
|
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
|
curl_setopt($curl, CURLOPT_FAILONERROR, false);
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($curl, CURLOPT_HEADER, false);
|
|
if (1 == strpos("$" . $host, "https://")) {
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
|
}
|
|
$callbcak = curl_exec($curl);
|
|
$CURLINFO_HTTP_CODE = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
|
//关闭,释放资源
|
|
curl_close($curl);
|
|
if ($CURLINFO_HTTP_CODE == 200)
|
|
return json_decode($callbcak, true);
|
|
}
|
|
|
|
private static function http_get_data($url) {
|
|
$ch = curl_init ();
|
|
curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, 'GET' );
|
|
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false );
|
|
curl_setopt ( $ch, CURLOPT_URL, $url );
|
|
ob_start ();
|
|
curl_exec ( $ch );
|
|
$return_content = ob_get_contents ();
|
|
ob_end_clean ();
|
|
$return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE );
|
|
return $return_content;
|
|
}
|
|
|
|
/**
|
|
* 一点零 ,测评商品列表
|
|
* *
|
|
* @param $page
|
|
* @param $testTypeId
|
|
* @return JsonResponse|string
|
|
*/
|
|
public static function testList($testTypeId,$page)
|
|
{
|
|
$keyUrl = self::$url.'/public-base/public-base-api/sign/getSign?appKey='.self::$key;
|
|
$result = self::http_get_data($keyUrl);
|
|
$URL = self::$url.'/cps/api/test/list';
|
|
$data['pageNo'] = $page ?? 1;
|
|
$data['pageSize'] = $request->perPage ?? 15;
|
|
$data['testCatId'] = $testTypeId ?? 1;
|
|
$data['source'] = 'cps-fulian';
|
|
$headers['appKey'] = self::$key;
|
|
$result = json_decode($result, true);
|
|
$headers['sign'] = $result['data']['sign'];
|
|
$headers['timestamp'] = $result['data']['timestamp'];
|
|
$headers = array(
|
|
"Accept: */*",
|
|
"Accept-Encoding: gzip, deflate",
|
|
"Cache-Control: no-cache",
|
|
"Connection: keep-alive",
|
|
"Content-Type: application/json;charset=utf-8",
|
|
"cache-control: no-cache",
|
|
"appKey: ".self::$key,
|
|
"sign: " . $result['data']['sign'],
|
|
"timestamp: " . $result['data']['timestamp'],
|
|
);
|
|
$result = self::curl($URL, 'POST', $headers, $data);
|
|
return $result['data'];
|
|
}
|
|
|
|
/**
|
|
* 一点零 ,获取测评题详情
|
|
* *
|
|
* @param $itemId
|
|
* @return JsonResponse|string
|
|
*/
|
|
public static function testDetails($itemId)
|
|
{
|
|
// 获取key
|
|
$keyUrl = self::$url.'/public-base/public-base-api/sign/getSign?appKey='.self::$key;
|
|
$result = self::http_get_data($keyUrl);
|
|
$URL = self::$url.'/cps/api/test/item/detail?itemId=' . $itemId . '&source=cps-fulian';
|
|
$headers['appKey'] = self::$key;
|
|
$result = json_decode($result, true);
|
|
$headers['sign'] = $result['data']['sign'];
|
|
$headers['timestamp'] = $result['data']['timestamp'];
|
|
$headers = array(
|
|
"Accept: */*",
|
|
"Accept-Encoding: gzip, deflate",
|
|
"Cache-Control: no-cache",
|
|
"Connection: keep-alive",
|
|
"Content-Type: application/json;charset=utf-8",
|
|
"cache-control: no-cache",
|
|
"appKey: ".self::$key,
|
|
"sign: " . $result['data']['sign'],
|
|
"timestamp: " . $result['data']['timestamp'],
|
|
);
|
|
$result = self::curl($URL, 'GET', $headers);
|
|
return $result['data'];
|
|
}
|
|
|
|
/**
|
|
* 一点零 ,评测下单
|
|
* *
|
|
* @param $itemId
|
|
* @param $amount
|
|
* @return JsonResponse|string
|
|
*/
|
|
public static function testCreate($itemId, $amount,$orderId)
|
|
{
|
|
// 获取key
|
|
$keyUrl = self::$url.'/public-base/public-base-api/sign/getSign?appKey='.self::$key;
|
|
$result = self::http_get_data($keyUrl);
|
|
|
|
$URL = self::$url.'/cps/api/test/create-order';
|
|
$headers['appKey'] = self::$key;
|
|
$result = json_decode($result, true);
|
|
$headers['sign'] = $result['data']['sign'];
|
|
$headers['timestamp'] = $result['data']['timestamp'];
|
|
$headers = array(
|
|
"Accept: */*",
|
|
"Accept-Encoding: gzip, deflate",
|
|
"Cache-Control: no-cache",
|
|
"Connection: keep-alive",
|
|
"Content-Type: application/json;charset=utf-8",
|
|
"cache-control: no-cache",
|
|
"appKey:".self::$key,
|
|
"sign: " . $result['data']['sign'],
|
|
"timestamp: " . $result['data']['timestamp'],
|
|
);
|
|
$data['orderId'] = $orderId;
|
|
$data['itemId'] = $itemId;
|
|
$data['source'] = 'cps-fulian';
|
|
$data['amount'] = $amount;
|
|
$data['openUserId'] = 321;
|
|
$result = self::curl($URL, 'POST', $headers, $data);
|
|
//$debug['input'] = json_encode($data);
|
|
//$debug['out'] = json_encode($result);
|
|
return $result['data'];
|
|
}
|
|
|
|
/**
|
|
* 一点零 ,测评订单状态更新
|
|
* *
|
|
* @param $orderId
|
|
*
|
|
*/
|
|
public static function testUpdate($orderId)
|
|
{
|
|
// 获取key
|
|
$keyUrl = self::$url.'/public-base/public-base-api/sign/getSign?appKey='.self::$key;
|
|
$result = self::http_get_data($keyUrl);
|
|
$URL = self::$url.'/cps/api/test/update-status';
|
|
$headers['appKey'] = self::$key;
|
|
$result = json_decode($result, true);
|
|
$headers['sign'] = $result['data']['sign'];
|
|
$headers['timestamp'] = $result['data']['timestamp'];
|
|
$headers = array(
|
|
"Accept: */*",
|
|
"Accept-Encoding: gzip, deflate",
|
|
"Cache-Control: no-cache",
|
|
"Connection: keep-alive",
|
|
"Content-Type: application/json;charset=utf-8",
|
|
"cache-control: no-cache",
|
|
"appKey: ".self::$key,
|
|
"sign: " . $result['data']['sign'],
|
|
"timestamp: " . $result['data']['timestamp'],
|
|
);
|
|
$data['orderId'] = $orderId;
|
|
//订单状态:1-未支付2-已支付3-支付失败
|
|
$data['orderStatus'] = 2;
|
|
$data['source'] = 'cps-fulian';
|
|
$result = self::curl($URL, 'POST', $headers, $data);
|
|
//$debug['input'] = json_encode($data);
|
|
//$debug['out'] = json_encode($result);
|
|
//\Log::info(json_encode($debug));
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* 一点零 ,提交评测题答案
|
|
* *
|
|
* @param $orderId
|
|
* @param $answer
|
|
* @param $itemId
|
|
* @return JsonResponse|string
|
|
*/
|
|
public static function testCommit($orderId,$itemId,$answer)
|
|
{
|
|
// 获取key
|
|
$keyUrl = self::$url.'/public-base/public-base-api/sign/getSign?appKey='.self::$key;
|
|
$result = self::http_get_data($keyUrl);
|
|
$URL = self::$url.'/cps/api/test/item/commit';
|
|
$headers['appKey'] = self::$key;
|
|
$result = json_decode($result, true);
|
|
$headers['sign'] = $result['data']['sign'];
|
|
$headers['timestamp'] = $result['data']['timestamp'];
|
|
$headers = array(
|
|
"Accept: */*",
|
|
"Accept-Encoding: gzip, deflate",
|
|
"Cache-Control: no-cache",
|
|
"Connection: keep-alive",
|
|
"Content-Type: application/json;charset=utf-8",
|
|
"cache-control: no-cache",
|
|
"appKey: ".self::$key,
|
|
"sign: " . $result['data']['sign'],
|
|
"timestamp: " . $result['data']['timestamp'],
|
|
);
|
|
$data['orderId'] = $orderId;
|
|
$data['itemId'] = $itemId;
|
|
$data['openUserId'] = 321;
|
|
$data['answer'] = $answer;
|
|
$data['source'] = 'cps-fulian';
|
|
$result = self::curl($URL, 'POST', $headers, $data);
|
|
$debug['input'] = $data;
|
|
$debug['out'] = $result['data'];
|
|
Log::info("请求一点零客服");
|
|
Log::info(json_encode($result, JSON_UNESCAPED_UNICODE));
|
|
return $result;
|
|
|
|
}
|
|
|
|
/**
|
|
* 一点零 ,获取测评报告
|
|
* *
|
|
* @param $orderId
|
|
* @return JsonResponse|string
|
|
*/
|
|
public static function testResult($orderId)
|
|
{
|
|
// 获取key
|
|
$keyUrl = self::$url.'/public-base/public-base-api/sign/getSign?appKey='.self::$key;
|
|
$result = self::http_get_data($keyUrl);
|
|
$URL = self::$url.'/cps/api/test/item/testResult';
|
|
$headers['appKey'] = self::$key;
|
|
$result = json_decode($result, true);
|
|
$headers['sign'] = $result['data']['sign'];
|
|
$headers['timestamp'] = $result['data']['timestamp'];
|
|
$headers = array(
|
|
"Accept: */*",
|
|
"Accept-Encoding: gzip, deflate",
|
|
"Cache-Control: no-cache",
|
|
"Connection: keep-alive",
|
|
"Content-Type: application/json;charset=utf-8",
|
|
"cache-control: no-cache",
|
|
"appKey: ".self::$key,
|
|
"sign: " . $result['data']['sign'],
|
|
"timestamp: " . $result['data']['timestamp'],
|
|
);
|
|
$data['orderId'] =$orderId;
|
|
$data['source'] = 'cps-fulian';
|
|
$result = self::curl($URL, 'POST', $headers, $data);
|
|
//$debug['input'] = json_encode($data);
|
|
//$debug['out'] = json_encode($result);
|
|
//\Log::info(json_encode($debug));
|
|
return $result['data'];
|
|
}
|
|
|
|
/**
|
|
* 服务关键字搜索
|
|
* @param $keyword
|
|
* @param $test_item_type
|
|
* @return mixed
|
|
*/
|
|
public static function searchEvaluate($keyword,$test_item_type){
|
|
return EvaluateList::when($keyword,function ($query) use ($keyword){
|
|
$query->where('name','like',"%$keyword%")
|
|
->orWhere('desc','like',"%$keyword%");
|
|
})
|
|
->when($test_item_type,function ($query) use($test_item_type){
|
|
$query->where('test_type',$test_item_type);
|
|
})
|
|
->get();
|
|
}
|
|
|
|
/**
|
|
*a获取一点灵报告
|
|
*/
|
|
public static function getYdlHtmlReport($url){
|
|
$html = file_get_contents($url);
|
|
$patten = '/(<div class="t200 z100 w100p")(.*)(?)(<span>保存结果并分享<\/span><\/a><\/div><\/div><\/div><\/div><\/div>)/';
|
|
preg_match_all($patten,$html,$title);
|
|
if(!empty($title[0][0])){
|
|
$return_title = $title[0][0];
|
|
}else {
|
|
return null;
|
|
}
|
|
$patten = '/(<head>)(.*)(?)(<\/head>)/';
|
|
preg_match_all($patten,$html,$head);
|
|
if(!empty($head[0][0])){
|
|
$return_head = $head[0][0];
|
|
}else {
|
|
return null;
|
|
}
|
|
$return_title = str_replace('<span>专业测评报告</span>','',$return_title);
|
|
$return_title = str_replace('<span>保存结果并分享</span>','',$return_title);
|
|
$return_html = $return_head.'<body>'.$return_title.'</body>';
|
|
return $return_html;
|
|
}
|
|
|
|
public static function commitDISC($answers)
|
|
{
|
|
$answers = json_decode($answers, true);
|
|
// $name = ["D", "I", "S", "C"];
|
|
$analysis = [''];
|
|
$d=$i=$s=$c = 0;
|
|
foreach ($answers as $answer) {
|
|
if ($answer['group_name'] == 'D') {
|
|
if ($answer['row_id'] % 5) {
|
|
$d += $answer['score'];
|
|
}
|
|
continue;
|
|
}
|
|
if ($answer['group_name'] == 'I') {
|
|
if ($answer['row_id'] % 5) {
|
|
$i += $answer['score'];
|
|
}
|
|
continue;
|
|
}
|
|
if ($answer['group_name'] == 'S') {
|
|
if ($answer['row_id'] % 5) {
|
|
$s += $answer['score'];
|
|
}
|
|
continue;
|
|
}
|
|
if ($answer['group_name'] == 'C') {
|
|
if ($answer['row_id'] % 5) {
|
|
$c += $answer['score'];
|
|
}
|
|
}
|
|
}
|
|
// $scores = ["D"=>$d, "I"=>$i, "S"=>$s, "C"=>$c];
|
|
// $name = $score = [];
|
|
// foreach ($scores as $key=> $sco){
|
|
// $name[] = $key;
|
|
// $score[] = $sco;
|
|
// }
|
|
$scores = [
|
|
['name'=>'D支配型', 'score'=>$d],
|
|
['name'=>'I影响型', 'score'=>$i],
|
|
['name'=>'S稳定型', 'score'=>$s],
|
|
['name'=>'C谨慎型', 'score'=>$c],
|
|
];
|
|
$name = $score = [];
|
|
foreach ($scores as $sco) {
|
|
$name[] = $sco['name'];
|
|
$score[] = $sco['score'];
|
|
}
|
|
|
|
return json_encode(['name'=>$name, 'score'=> $score, 'analysis'=>$analysis]);
|
|
}
|
|
|
|
/**
|
|
* 一点零 ,分销订单查询
|
|
*/
|
|
|
|
/**
|
|
* 一点零 ,退款工单申请
|
|
*/
|
|
|
|
/**
|
|
* 一点零 ,分销订单查询
|
|
*/
|
|
|
|
}
|