为了账号安全,请及时绑定邮箱和手机立即绑定

我怎样才能从拉拉维尔5.3的咕噜声中得到回应

我怎样才能从拉拉维尔5.3的咕噜声中得到回应

PHP
慕哥6287543 2022-09-12 13:00:14
我试试像这样:$client = new Client();$res = $client->request('POST', 'https://api.orange.com/smsmessaging/v1/outbound/tel:+phone/requests/', [            'headers' => [                'Accept' => 'application/json',                'Content-Type' => 'application/json',                'Authorization'=>'Bearer '.$token,                /*'Content-Type' => 'application/x-www-form-urlencoded',*/            ],            /*'form_params' => $body ,*/            'json' => [                'outboundSMSMessageRequest'=>[                'address'=> 'tel:+$phone',                'senderAddress'=>'tel:+phone_rec',                'outboundSMSTextMessage'=>[                     'message'=> 'Hello test!'                ]            ]],            'debug'   => true,            'verify' => false,                ]        );        $res->getStatusCode();        // 200        $res->getHeader('content-type');        // 'application/json; charset=utf8'        $res->getBody();执行时,结果是错误curl_setopt_array():不能将输出类型的流表示为 STDIO FILE* 如何获取响应?我在邮递员中尝试,它的成功得到回应但是我尝试使用咕噜声,它失败了
查看完整描述

2 回答

?
慕村9548890

TA贡献1884条经验 获得超4个赞

您可以尝试以下代码:


try {

    $client = new Client();

    $token = 'token';

    $res = $client->request('POST', 'https://api.orange.com/smsmessaging/v1/outbound/tel:+phone/requests/', [

            'headers' => [

                'Content-Type' => 'application/json',

                'Authorization'=>'Bearer '. $token,

            ],

            'json' => [

                'outboundSMSMessageRequest'=>[

                    'address'=> "tel:youre-phone",

                    'senderAddress'=>'tel:+phone_rec',

                    'outboundSMSTextMessage'=>[

                        'message'=> 'Hello test!'

                    ]

                ]],

            'debug'   => true,

            'verify' => false,

        ]

    );

    echo $res->getBody();

} catch ( \GuzzleHttp\Exception\ClientException $exception ) {

    echo $exception->getResponse()->getBody();

}


查看完整回答
反对 回复 2022-09-12
?
猛跑小猪

TA贡献1858条经验 获得超8个赞

我这样解决了


 $requestContent = [

            'headers' => [

                'Accept' => 'application/json',

                'Content-Type' => 'application/json',

                'Authorization'=>'Bearer '.$token,

            ],

            'json' => [

                'outboundSMSMessageRequest'=>[                        

                'address'=> "tel:youre-phone",

                'senderAddress'=>'tel:+phone_rec',

                    'outboundSMSTextMessage'=>[

                        'message'=> 'Hello test !'

                    ]

                ]

            ]

        ];

        try {

            $client = new Client();

            $res = $client->request('POST', 'https://api.orange.com/smsmessaging/v1/outbound/tel:+phone_rec/requests/', $requestContent);

            $response = json_decode($res->getBody());

            dd($response);

        } catch (RequestException $re) {


        }


查看完整回答
反对 回复 2022-09-12
  • 2 回答
  • 0 关注
  • 52 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信