post事件时LINE BOT API内部错误(500),get事件时成功


LINE BOT API internal error (500) on post event but success on get event

我使用LINE BOT API发送了许多curl格式的消息,但总是得到500错误。

这是我的最后一个post curl代码

$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."
]
这是我的get代码(process 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服务器)的错误吗?
任何建议和答案都会对我有帮助。非常感谢。

您可以尝试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