关于事件后的LINE BOT API内部错误(500)但是在get事件上成功

时间:2016-08-19 02:56:55

标签: php api

我使用LINE BOT API发送了很多卷曲格式,但总是得到500错误。

这是我上一篇帖子卷曲代码

$apiCall = 'https://trialbot-api.line.me/v1/events';

$params = array();
$params['to'] = ["uf92dfc2702b46be071376c8ff81a4b56"];
$params['toChannel'] = 1383378250;
$params['eventType'] = "138311608800106203";
$params['content'] = [ "contentType" => 1,
                       "toType" => 1,
                       "text" => "the text"];
$string_data = json_encode($params)

$headers = array (
            "Content-Type: application / json; charset = UTF-8",
            "X-Line-ChannelID: 1476460XXX",
            "X-Line-ChannelSecret: 6363d24b1e356c77189137b6362XXXXX",
            "X-Line-Trusted-User-With-ACL: u54bf222a19fd3114e9eb1a3499dXXXXX"
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiCall);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, count($params));
curl_setopt($ch, CURLOPT_POSTFIELDS, $string_data);
$jsonData = curl_exec($ch);
curl_close($ch);

$results = json_decode($jsonData,TRUE);

这是结果

array:2 [
  "statusCode" => "500"
  "statusMessage" => "internal error."
]

这是我的获取代码(proccess successfully)

$url = "https://trialbot-api.line.me/v1/profiles?mids=uc02643a656b777f66162e121fa697f82";
$curl = curl_init ($url) ;
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
     'Content-Type: application/json; charset = UTF-8',
     'X-Line-ChannelID: 1476460XXX',
     'X-Line-ChannelSecret: 6363d24b1e356c77189137b6362XXXXX',
     'X-Line-Trusted-User-With-ACL: u54bf222a19fd3114e9eb1a3499dXXXXX')
);
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, true );
$output = curl_exec ($curl) ;
curl_close($curl);

问题是:

  1. 为什么我的代码在GET事件上成功运行但在POST事件上没有成功?
  2. 错误500是来自服务器(LINE服务器)的错误吗?
  3. 任何建议和答案都会对我有所帮助。 非常感谢。

1 个答案:

答案 0 :(得分:0)

您可以尝试此curl请求发送消息:

curl -X POST \
-H 'Content-Type: application/json; charset=UTF-8' \
-H 'X-Line-ChannelID: 147XXXX741' \   //your channel ID
-H 'X-Line-ChannelSecret: ff9051XXXXXXb5531e3eb633b24c2e73' \   //Your channel Secret
-H 'X-Line-Trusted-User-With-ACL: uc866bXXXXXX8b4fbc3f4dd43befd66c9' \  //Your channel mid
-d '{
   "to":["u004ddf56dXXXXXb2f9760e02f0a7b623"], //List of users MID
   "toChannel": 1383378250, //Fixed
   "eventType": "138311608800106203", //Fixed
   "content":{
       "contentType":1,
       "toType":1,
       "text":"hallo"
   }
}' https://trialbot-api.line.me/v1/events