0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PHP から Chatwork にメッセージを送信

Last updated at Posted at 2018-11-10

PHP から Chatwork にメッセージを送信

まずは動かしてみる Hello world 的なサンプル。

Step1.

composer require kitchenu/chatwork-php

Step2.

ここから Chatwork の API Token を発行してきます。
https://www.chatwork.com/service/packages/chatwork/subpackages/api/token.php

Step3.

送信先 RoomID は 送信したい chatwork のルームのURLを確認します。
もし、URL が https://www.chatwork.com/#!rid1234xxxx だったら 1234xxxx の部分が RoomID です。

<?php
	require_once "vendor/autoload.php";
 
	$token = "591aaec4xxxxxxxxxxxxxxxxxxxxxxxx";		// chatwork api token
	$options = [		// 内部で使われてる GuzzleHttp Client に渡す オプション
		'verify' => false,		// false にすると SSL証明書確認しない。通常は true が望ましい。
	];
	$chatwork = new \Kitchenu\Chatwork\Client($token, $options);

	$room = "1234xxxx";
	$message = "Hello world.";
	$unread = 1;	// 0:既読 1:未読
	$chatwork->postRoomMessages([
		'room_id' => $room,
		'body' => $message,
		'self_unread' => $unread
	]);

	// 送信完了

以上で送信完了


  • Composer に wataridori/chatwork-sdkpolidog/php-chatwork-api もあったが、中身のソースコードも確認した結果、 kitchenu/chatwork-php というパッケージがシンプルで使いやすいと思います。
  • Exception SSL certificate problem: unable to get local issuer certificate が出る場合 $options = [ 'verify' => false ] で一時的に回避
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?