伊莉討論區

標題: php 串接LINE notify 的方法 [打印本頁]

作者: daneil4444    時間: 2018-8-27 10:33 PM     標題: php 串接LINE notify 的方法

各位大大好
最近要做一個自動推送line訊息給用戶的功能必須串接LINE notify這玩意兒..
查過很多資料幾乎都是取用戶token再用postman程式來送訊息
但是我想用php請問該如何寫呢?
去他們官網看也沒有這方面說明
麻煩各位幫幫忙
作者: chengpocheng    時間: 2018-8-30 10:57 AM

本帖最後由 chengpocheng 於 2018-8-30 10:58 AM 編輯

可以使用php_curl
就看LINE notify提供的接口是用POST GET PUT...等

舉例來說
  1. $send_url = "http://example.com";
  2. $token_post = array(
  3.     "code" => "testCode",
  4.     "client_id" => "testClient",
  5.     "client_secret" =>”testScecret”,
  6. );

  7. $ch = curl_init();
  8. curl_setopt($ch, CURLOPT_URL, $send_url);
  9. curl_setopt($ch, CURLOPT_POSTFIELDS, $token_post);
  10. curl_setopt($ch, CURLOPT_RETURNTRANSFER , 1);
  11. $response = curl_exec($ch); // 回傳 access_token
  12. curl_close($ch);
複製代碼
因為我沒看line notify的串接文件,變數token_post裡面的參數要靠你自行去查閱,但根據我的經驗,取得access token的流程差不多就是這樣
作者: daneil4444    時間: 2018-8-30 02:04 PM

本帖最後由 daneil4444 於 2018-8-30 03:06 PM 編輯
chengpocheng 發表於 2018-8-30 10:57 AM
可以使用php_curl
就看LINE notify提供的接口是用POST GET PUT...等

剛去試成功取得access_token我後來找到參數了,順便貼在下面
  1. $token_post = array(
  2.     "grant_type" => "authorization_code",
  3.     "redirect_uri" => "******",        
  4.     "code" => "*****",
  5.     "client_id" => "******",
  6.     "client_secret" =>"*********",
  7. );
複製代碼
成功推送!@chengpocheng謝拉
作者: daneil4444    時間: 2018-8-30 02:06 PM

chengpocheng 發表於 2018-8-30 10:57 AM
可以使用php_curl
就看LINE notify提供的接口是用POST GET PUT...等

剛去找參數成功取得access token,順便貼在下面
$token_post = array(
    "grant_type" => "authorization_code",
    "redirect_uri" => "http://localhost/",       
    "code" => "***********",
    "client_id" => "***************",
    "client_secret" =>"**************",
);
已成功推送!@chengpocheng謝嚕
作者: xiaofu95    時間: 2018-9-12 04:52 PM

不錯哦!謝謝各位的分享++




歡迎光臨 伊莉討論區 (http://www72.eyny.com/) Powered by Discuz!