php cURL发布为json to pushbullet

时间:2016-12-09 10:54:00

标签: php curl pushbullet

我想通过Android手机发送短信。我找到了一个很有前途的api来做pushbullet

关于通过cURL连接到它的部分说我应该添加自定义标头Access-Token: <your_access_token_here>'。我在php中添加了它,但curl_exec返回false。在PostMan上我可以毫无问题地创建它。我创建cURL的函数如下所示:

    public function getUrlContent($url, $post)
    {
        $data_string = '{
  "push": {
    "conversation_iden": "+3 34333333",
    "message": "Hello!",
    "package_name": "com.pushbullet.android",
    "source_user_iden": "qwerqwerqwer",
    "target_device_iden": "erqwer",
    "type": "messaging_extension_reply"
  },
  "type": "push"
}';
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Access-Token: xxxxxxxxxxxxxxxxxxxx',
        'Content-Length: '.strlen($data_string), )
        );

        $result = curl_exec($ch);


        curl_close($ch);

        return $result;
    }

0 个答案:

没有答案