|
@@ -10,21 +10,25 @@ class MayCurServerService extends Service
|
|
{
|
|
{
|
|
protected $param = "";
|
|
protected $param = "";
|
|
protected $domain_url = "";
|
|
protected $domain_url = "";
|
|
|
|
+ protected $head = null;
|
|
|
|
|
|
public function __construct()
|
|
public function __construct()
|
|
{
|
|
{
|
|
$this->param = config("maycur");
|
|
$this->param = config("maycur");
|
|
- $this->domain_url = $this->param['zs_url'];
|
|
|
|
|
|
+ $this->domain_url = $this->param['dd_url'];
|
|
}
|
|
}
|
|
|
|
|
|
- public function getToken($data){
|
|
|
|
|
|
+ public function getToken(){
|
|
//每刻所有配置
|
|
//每刻所有配置
|
|
$url_array = $this->param;
|
|
$url_array = $this->param;
|
|
|
|
|
|
//redis 存储的token
|
|
//redis 存储的token
|
|
$key = $this->domain_url . $url_array['login_redis_topic'];
|
|
$key = $this->domain_url . $url_array['login_redis_topic'];
|
|
$token = Redis::get($key);
|
|
$token = Redis::get($key);
|
|
- if(! empty($token)) return [true, json_decode($token,true)];
|
|
|
|
|
|
+ if(! empty($token)) {
|
|
|
|
+ $this->head = json_decode($token,true);
|
|
|
|
+ return [true, ''];
|
|
|
|
+ }
|
|
|
|
|
|
//获取token的参数
|
|
//获取token的参数
|
|
$appcode = env('maycur_appcode');
|
|
$appcode = env('maycur_appcode');
|
|
@@ -34,7 +38,7 @@ class MayCurServerService extends Service
|
|
//组织获取参数
|
|
//组织获取参数
|
|
$url = $this->domain_url . $url_array['login'];
|
|
$url = $this->domain_url . $url_array['login'];
|
|
$time = microtime(true);
|
|
$time = microtime(true);
|
|
- $timeStamp = round($time * 1000);
|
|
|
|
|
|
+ $timeStamp = intval($time * 1000);
|
|
//生成secret
|
|
//生成secret
|
|
$secret = $this->getSecret($appcode, $appsercet, $timeStamp);
|
|
$secret = $this->getSecret($appcode, $appsercet, $timeStamp);
|
|
|
|
|
|
@@ -46,15 +50,17 @@ class MayCurServerService extends Service
|
|
$header = ['Content-Type:application/json'];
|
|
$header = ['Content-Type:application/json'];
|
|
list($status, $result) = $this->post_helper($url,$post, $header);
|
|
list($status, $result) = $this->post_helper($url,$post, $header);
|
|
if(! $status) return [$status, $result];
|
|
if(! $status) return [$status, $result];
|
|
- if(empty($result['data']['entCode']) || empty($result['data']['tokenId'])) return [false, $result['message'] ?? '鉴权失败,请联系开发者'];
|
|
|
|
|
|
+ if(isset($result['code']) && $result['code'] != 'ACK') return [false, $result['message'] ?? '鉴权失败,请联系开发者'];
|
|
|
|
|
|
$token_array = [
|
|
$token_array = [
|
|
- 'entCode' => $result['data']['entCode'],
|
|
|
|
- 'tokenId' => $result['data']['tokenId'],
|
|
|
|
|
|
+ 'tokenId:' . $result['data']['tokenId'],
|
|
|
|
+ 'entCode:' . $result['data']['entCode'],
|
|
];
|
|
];
|
|
|
|
+ $this->head = $token_array;
|
|
|
|
+
|
|
Redis::setex($key, $url_array['login_expire_time'], json_encode($token_array));
|
|
Redis::setex($key, $url_array['login_expire_time'], json_encode($token_array));
|
|
|
|
|
|
- return [true, $token_array];
|
|
|
|
|
|
+ return [true, ''];
|
|
}
|
|
}
|
|
|
|
|
|
private function getSecret($appCode, $appSecret, $timeStamp) {
|
|
private function getSecret($appCode, $appSecret, $timeStamp) {
|
|
@@ -65,8 +71,108 @@ class MayCurServerService extends Service
|
|
return $hashedString;
|
|
return $hashedString;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public function reimburse($data){
|
|
|
|
+ //校验
|
|
|
|
+ list($status, $msg) = $this->reimburseRule($data);
|
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
|
+ //获取token
|
|
|
|
+ list($status, $token) = $this->getToken();
|
|
|
|
+ if(! $status) return [false, $token];
|
|
|
|
+
|
|
|
|
+ $header = $this->head;
|
|
|
|
+ //每刻所有配置
|
|
|
|
+ $url_array = $this->param;
|
|
|
|
+ //组织获取参数
|
|
|
|
+ $url = $this->domain_url . $url_array['reimburse'];
|
|
|
|
+ $header = array_merge(['Content-Type:application/json'], $header);
|
|
|
|
+ list($status, $result) = $this->post_helper($url,$msg, $header);
|
|
|
|
+ if(! $status) return [$status, $result];
|
|
|
|
+ if(isset($result['code']) && $result['code'] != 'ACK') return [false, $result['message']];
|
|
|
|
+
|
|
|
|
+ //组织返回数据
|
|
|
|
+ if(empty($result['data'])) return [true, $result['data']];
|
|
|
|
+
|
|
|
|
+ //获取报销单详情填充
|
|
|
|
+ list($status, $return) = $this->reimburseDetailGet($result['data']);
|
|
|
|
+ if(! $status) return [false, $return];
|
|
|
|
+
|
|
|
|
+ return [true, $return];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function reimburseRule($data){
|
|
|
|
+ if(empty($data['createdAtStart']) || empty($data['createdAtEnd'])) return [false, '单据的创建时间不能为空'];
|
|
|
|
+ $createAtStart = strtotime($data['createdAtStart'] . '00:00:00');
|
|
|
|
+ $createdAtEnd = strtotime($data['createdAtEnd'] . '23:59:59');
|
|
|
|
+ if(empty($createAtStart)) return [false, '单据的创建开始时间格式错误'];
|
|
|
|
+ if(empty($createdAtEnd)) return [false, '单据的创建结束时间格式错误'];
|
|
|
|
+
|
|
|
|
+ $pageNo = 1;
|
|
|
|
+ $pageSize = 10;
|
|
|
|
+ if(! empty($data['pageNo'])) $pageNo = $data['pageNo'];
|
|
|
|
+ if(! empty($data['pageSize'])) {
|
|
|
|
+ if($data['pageSize'] >= 100) {
|
|
|
|
+ $pageSize = 10;
|
|
|
|
+ }else{
|
|
|
|
+ $pageSize = $data['pageSize'];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $return = [
|
|
|
|
+ 'createdAtStart' => $createAtStart * 1000,
|
|
|
|
+ 'createdAtEnd' => $createdAtEnd * 1000,
|
|
|
|
+ 'pageNo' => $pageNo,
|
|
|
|
+ 'pageSize' => $pageSize,
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ return [true, $return];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function reimburseDetailGet($list){
|
|
|
|
+ if(empty($list['list'])) return [true, $list];
|
|
|
|
+
|
|
|
|
+ foreach ($list['list'] as $key => $value){
|
|
|
|
+ list($status, $msg) = $this->reimburseDetail($value);
|
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
|
+
|
|
|
|
+ $list['list'][$key]['reimburseDetail'] = $msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return [true, $list];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function reimburseDetail($data){
|
|
|
|
+ if(empty($data['formCode'])) return [false, ["报销单详情请求缺失formCode"]];
|
|
|
|
+
|
|
|
|
+ $post = [
|
|
|
|
+ "formCode"=> $data['formCode'],
|
|
|
|
+ "enablePayeeInfo"=> true,
|
|
|
|
+ "enablePayerInfo"=> true,
|
|
|
|
+ "enableAssociatedForms"=> true,
|
|
|
|
+ "enableTravelRouteList"=> true,
|
|
|
|
+ "enableCreditInfo"=> true,
|
|
|
|
+ "enableExpenseList"=> true,
|
|
|
|
+ "enableInvoiceList"=> true,
|
|
|
|
+ "enableExpenseAllocationList"=> true,
|
|
|
|
+ "enableTravelPartnerInfo"=> true,
|
|
|
|
+ "enableAttachments"=> true,
|
|
|
|
+ "enableCapitalPlanPaymentLog"=> true
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ $header = $this->head;
|
|
|
|
+ //每刻所有配置
|
|
|
|
+ $url_array = $this->param;
|
|
|
|
+ //组织获取参数
|
|
|
|
+ $url = $this->domain_url . $url_array['reimburseDetail'];
|
|
|
|
+ $header = array_merge(['Content-Type:application/json'], $header);
|
|
|
|
+ list($status, $result) = $this->post_helper($url,$post, $header);
|
|
|
|
+ if(! $status) return [$status, $result];
|
|
|
|
+ if(isset($result['code']) && $result['code'] != 'ACK') return [false, $result['message']];
|
|
|
|
+
|
|
|
|
+ return [true, $result['data'] ?? []];
|
|
|
|
+ }
|
|
|
|
+
|
|
public function post_helper($url, $data, $header = [], $timeout = 20){
|
|
public function post_helper($url, $data, $header = [], $timeout = 20){
|
|
- Log::channel('apiLog')->info('每刻POST', ["api" => $url , "param" => $data ,"header" => $header]);
|
|
|
|
|
|
+ Log::channel('apiMcLog')->info('每刻POST', ["api" => $url , "param" => $data ,"header" => $header]);
|
|
|
|
|
|
$ch = curl_init();
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
@@ -88,19 +194,19 @@ class MayCurServerService extends Service
|
|
$errorMessage = curl_error($ch);
|
|
$errorMessage = curl_error($ch);
|
|
$message = "cURL Error #{$errorNumber}: {$errorMessage}";
|
|
$message = "cURL Error #{$errorNumber}: {$errorMessage}";
|
|
|
|
|
|
- Log::channel('apiLog')->info('每刻POST结果', ["message" => $message]);
|
|
|
|
|
|
+ Log::channel('apiMcLog')->info('每刻POST结果', ["message" => $message]);
|
|
return [false, $message];
|
|
return [false, $message];
|
|
}
|
|
}
|
|
curl_close($ch);
|
|
curl_close($ch);
|
|
|
|
|
|
$return = json_decode($r, true);
|
|
$return = json_decode($r, true);
|
|
- Log::channel('apiLog')->info('每刻POST结果', ["message" => $return]);
|
|
|
|
|
|
+ Log::channel('apiMcLog')->info('每刻POST结果', ["message" => $return]);
|
|
|
|
|
|
return [true, $return];
|
|
return [true, $return];
|
|
}
|
|
}
|
|
|
|
|
|
public function get_helper($url,$header=[],$timeout = 20){
|
|
public function get_helper($url,$header=[],$timeout = 20){
|
|
- Log::channel('apiLog')->info('每刻GET', ["api" => $url ,"header" => $header]);
|
|
|
|
|
|
+ Log::channel('apiMcLog')->info('每刻GET', ["api" => $url ,"header" => $header]);
|
|
$ch = curl_init();
|
|
$ch = curl_init();
|
|
curl_setopt_array($ch, array(
|
|
curl_setopt_array($ch, array(
|
|
CURLOPT_URL => $url,
|
|
CURLOPT_URL => $url,
|
|
@@ -122,14 +228,14 @@ class MayCurServerService extends Service
|
|
// 获取错误信息
|
|
// 获取错误信息
|
|
$errorMessage = curl_error($ch);
|
|
$errorMessage = curl_error($ch);
|
|
$message = "cURL Error #{$errorNumber}: {$errorMessage}";
|
|
$message = "cURL Error #{$errorNumber}: {$errorMessage}";
|
|
- Log::channel('apiLog')->info('每刻GET', ["message" => $message]);
|
|
|
|
|
|
+ Log::channel('apiMcLog')->info('每刻GET', ["message" => $message]);
|
|
return [false, $message];
|
|
return [false, $message];
|
|
}
|
|
}
|
|
|
|
|
|
curl_close($ch);
|
|
curl_close($ch);
|
|
|
|
|
|
$return = json_decode($r, true);
|
|
$return = json_decode($r, true);
|
|
- Log::channel('apiLog')->info('每刻GET', ["message" => $return]);
|
|
|
|
|
|
+ Log::channel('apiMcLog')->info('每刻GET', ["message" => $return]);
|
|
|
|
|
|
return [true, $return];
|
|
return [true, $return];
|
|
}
|
|
}
|