'深圳亿起融网络科技有限公司', //购买方名称 // 'buyerType' => '01', //购买方类型01:企业 // 'buyerTaxNo' => '91440300326621149M', //购买方税号 // 'totalAmountTax' => '100.00', //总金额含税 // 'manualOrderDetails' => [[ // 'amount' => '100.00', //金额 // 'invoiceNature' => '0', //0:正常 1:折扣 2:被折扣 // 'itemName' => '山海经', //商品名称 // 'itemTaxCode' => '3049900000000000000', //商品税号 // 'taxIncluded' => '1', //1:含税0:不含税 // 'taxRate' => '0.06',//税率 // 'yhzcbs' => '0',//优惠政策标识 // ]], // ]; $headers = array( CURLOPT_HTTPHEADER => array( 'Content-Type:application/json;charset=UTF-8', 'Accept:application/json;charset=UTF-8', 'Authorization:bearer ' . $this->InvoiceRequestToken(), 'taxNo:440301999999980', 'machineNo:2', ), ); $data = json_encode($data); // $header = json_encode($header); $aes = new security(); $httphelper = new HttpHelper(); // $result = $httphelper->send_post_info($openapiurl, $data, $header); $result = Http::post($openapiurl, $data, $headers); return json_decode($result['data'], true); } /** * Notes:发票申请token * User: torsenli * Date: 2022/4/8 * Time: 18:05 */ public function InvoiceRequestToken() { // header('content-type:application/json;charset=utf8'); header('content-type:application/json;charset=utf8'); $token = Cache::get('IRToken'); if (!$token) { $openapiurl = "https://demo.szhtxx.cn:18182/apiv2/oauth/token"; $data = [ 'client_id' => 'apiuser', 'client_secret' => 'secret', 'grant_type' => 'password', 'username' => '440301999999980', 'password' => '123456', ]; $aes = new security(); $httphelper = new HttpHelper(); $result = $httphelper->send_post($openapiurl, $data); $val = json_decode($result, true); Cache::set('IRToken', $val['access_token'], 3600); return $val['access_token']; } else { return $token; } } }