Test.php 3.22 KB
<?php

namespace addons\qingdong\controller;

use addons\qingdong\model\Amodel;
use addons\qingdong\model\Customer;
use Complex\Exception;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;

class Test extends StaffApi
{
    protected $noNeedLogin = ['*'];

    public function index(){

        //$data2 = Amodel::where('bill_id' , 19)->where('type','goods')->find();
        $data2['json'] = '[{"no":1,"productName":"\u9ed8\u8ba4\u5546\u54c1","markingModel":"\u9ed8\u8ba4","brand":"","unit":"\u4e2a","qty":1,
        "unitPrice":"100","amount":"100","productParameter":"","productPicture":""}]';

        $client = new Client();
        $headers = [
            'Content-Type' => 'application/json'
        ];
        $url = 'http://113.250.185.56:8089/api/office/excel';


        //halt(json_decode($data2['json'], true));
        $body = [
            'email' => 'bosiny@bosiny.com',
            'contacts'=>'ss',
            'mobile' => 'ss',
            'items' =>json_decode($data2['json'], true),

        ];

        $request = new Request('POST', $url, $headers, json_encode($body));
        $res = $client->sendAsync($request)->wait();


        $this->success('',$res->getBody()->getContents());

    }

    public function index2(){

        //$data2 = Amodel::where('bill_id' , 60)->where('type','contract')->find();
        $data2['json'] = '{"\u7532\u65b9":"\u535a\u897f\u5c3c\u4fe1\u606f\u79d1\u6280\u6709\u9650\u516c\u53f8","\u4e59\u65b9":"\u56db\u5ddd\u6d77\u94ed\u7535\u5b50"}';

        $client = new Client();
        $headers = [
            'Content-Type' => 'application/json'
        ];
        $url = 'http://113.250.185.56:8089/api/office';

        $body = array(
            'downName' => '',
            'content' => $data2['json'],
            'templateName' => ''
        );

        //halt(json_encode($body));

        $request = new Request('POST', $url, $headers, json_encode($body));
        $res = $client->sendAsync($request)->wait();


        $this->success('',$res);

    }

    public function index3(){

        $url = 'http://113.250.185.56:8089/api/office/excel';

        $data2['json'] = '[{"no":1,"productName":"\u9ed8\u8ba4\u5546\u54c1","markingModel":"\u9ed8\u8ba4","brand":"","unit":"\u4e2a","qty":1,
        "unitPrice":100,"amount":100,"productParameter":"\u9ed8\u8ba4\u5546\u54c1","productPicture":"\u9ed8\u8ba4\u5546\u54c1"}]';

        $body = json_encode([
            'email' => 'bosiny@bosiny.com',
            'contacts'=>'ss',
            'mobile' => 'ss',
            'items' =>$data2['json'],
        ]);

        // 初始化 cURL
        $curl = curl_init($url);

        // 设置 cURL 选项
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
        curl_setopt($curl, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json',
            'Content-Length: ' . strlen($body)
        ));
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

        // 执行 cURL 请求并获取响应
        $response = curl_exec($curl);

        // 关闭 cURL 资源
        curl_close($curl);

        // 处理响应
        echo $response;

    }


}