123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- namespace app\common\util\SysSDK\Baidu;
- use think\facade\Log;
- class Identify {
-
- private $vi_url = Config::get('baidu.request.vi_url');
- private $viv_url = Config::get('baidu.request.viv_url');
- private $url = Config::get('baidu.request.oauth_url');
- private $client_id = Config::get('baidu.request.client_id');
- private $client_secret = Config::get('baidu.request.client_secret');
-
- public function refresh(){
- $post_data['grant_type'] = 'client_credentials';
- $post_data['client_id'] = $this->client_id;
- $post_data['client_secret'] = $this->client_secret;
- $o = "";
- foreach ( $post_data as $k => $v )
- {
- $o.= "$k=" . urlencode( $v ). "&" ;
- }
- $post_data = substr($o,0,-1);
-
- $data = $this->curl($this->url, $post_data);
- Log::info(' get access_token result:'.json_encode($data));
- return $data;
- }
-
- public function vat_invoice($access_token, $files){
- $file_name_array = explode('.', $files);
- if(count($file_name_array) < 2){
- return false;
- }
- $suffix = $file_name_array[count($file_name_array)-1];
-
- if(in_array(strtolower($suffix), ['jpg','jpeg','png','bmp'])){
- $param_type = 'image';
- }
- else if(strtolower($suffix) == 'pdf'){
- $param_type = 'pdf_file';
- }
- else{
- return false;
- }
- $img = file_get_contents($files);
- $img = base64_encode($img);
- $param = array(
- $param_type => $img
- );
-
- $data = $this->curl($this->vi_url.'?access_token='.$access_token, $param);
- Log::info(' get result:'.json_encode($data));
- return $data;
- }
-
-
-
- public function vat_invoice_verification($access_token, $invoice_code, $invoice_num, $invoice_date, $invoice_type, $check_code, $total_amount){
- $bodys = array(
- 'invoice_code' => $invoice_code,
- 'invoice_num' => $invoice_num,
- 'invoice_date' => $invoice_date,
- 'check_code' => $check_code,
- 'invoice_type' => $invoice_type,
- 'total_amount' => $total_amount,
- );
-
- $data = $this->curl($this->viv_url.'?access_token='.$access_token, $bodys);
- Log::info(' get result:'.json_encode($data));
- return $data;
- }
- private function curl($url = '', $param = '')
- {
- if (empty($url) || empty($param)) {
- return false;
- }
- $postUrl = $url;
- $curlPost = $param;
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, $postUrl);
- curl_setopt($curl, CURLOPT_HEADER, 0);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($curl, CURLOPT_POST, 1);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost);
- $data = curl_exec($curl);
-
- Log::info(' get curl result:' . json_encode($data));
- curl_close($curl);
- return $data;
- }
- }
|