Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

message/push 接口应该支持 POST json 调用方式 #41

Closed
kikyous opened this issue Jan 29, 2022 · 4 comments
Closed

message/push 接口应该支持 POST json 调用方式 #41

kikyous opened this issue Jan 29, 2022 · 4 comments

Comments

@kikyous
Copy link

kikyous commented Jan 29, 2022

POST https://api2.pushdeer.com/message/push

content-type: application/json
{
    "pushkey": "...",
    "text": "Hello World!",
}
@easychen
Copy link
Owner

加上了。9d7654c

@kikyous
Copy link
Author

kikyous commented Feb 1, 2022

还没有部署到正式服务器吗?

@easychen
Copy link
Owner

easychen commented Feb 1, 2022

<?php

// get cURL resource
$ch = curl_init();

// set url
curl_setopt($ch, CURLOPT_URL, 'https://api2.pushdeer.com/message/push');

// set method
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');

// return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// set headers
curl_setopt($ch, CURLOPT_HTTPHEADER, [
  'Content-Type: application/json; charset=utf-8',
]);

// json body
$json_array = [
  'pushkey' => 'PUSHKEY',
  'text' => 'IMGURL',
  'type' => 'image'
]; 
$body = json_encode($json_array);

// set body
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);

// send the request and save response to $response
$response = curl_exec($ch);

// stop if fails
if (!$response) {
  die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
}

echo 'HTTP Status Code: ' . curl_getinfo($ch, CURLINFO_HTTP_CODE) . PHP_EOL;
echo 'Response Body: ' . $response . PHP_EOL;

// close curl resource to free up system resources 
curl_close($ch);

返回

HTTP Status Code: 200
Response Body: {"code":0,"content":{"result":["{\"counts\":1,\"logs\":[],\"success\":\"ok\"}","{\"counts\":1,\"logs\":[],\"success\":\"ok\"}","{\"counts\":1,\"logs\":[{\"result\":\"ok\",\"trace_id\":\"Xcm62472643689853772Vq\",\"code\":0,\"data\":{\"id\":\"scm62472643689853783fZ\"},\"description\":\"\\u6210\\u529f\",\"info\":\"Received push messages for 1 REGID\"}]}"]}}

@kikyous
Copy link
Author

kikyous commented Feb 1, 2022

可以了,感谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants