Wechaty is a Conversational SDK for Chatbot Makers that can help you create a bot in 8 lines of PHP
"Wechaty is a great solution, I believe there would be much more users recognize it." link
— @Gcaufy, Tencent Engineer, Author of WePY"太好用,好用的想哭"
— @xinbenlv, Google Engineer, Founder of HaoShiYou.org"最好的微信开发库" link
— @Jarvis, Baidu Engineer"Wechaty让运营人员更多的时间思考如何进行活动策划、留存用户,商业变现" link
— @lijiarui, Founder & CEO of Juzi.BOT."If you know js ... try Wechaty, it's easy to use."
— @Urinx Uri Lee, Author of WeixinBot(Python)
See more at Wiki:Voice Of Developer
Wechaty is used in many ChatBot projects by thousands of developers. If you want to talk with other developers, just scan the following QR Code in WeChat with secret code php wechaty, join our Wechaty PHP Developers' Home.
Scan now, because other Wechaty PHP developers want to talk with you too! (secret code: php wechaty)
- PHP Wechaty Starter Repository for Docker - https://github.com/wechaty/docker-php-wechaty-getting-started
PHP Wechaty Docker supports PHP Script.
2.1. Run php script
# for php script
docker run -ti --volume="$(pwd)":/bot --rm phpwechaty/php-wechaty:v1 docker/ding-dong-bot.php
Learn more about Wechaty Docker at Wiki:Docker.
WECHATY_PUPPET_SERVICE_TLS_CA_CERT
: can be overwrite byoptions.tlsRootCert
. Set Root CA Cert to verify the server or client.
For Puppet Server:
Environment Variable | Options | Description |
---|---|---|
WECHATY_PUPPET_SERVICE_TLS_SERVER_CERT |
options.tls.serverCert |
Server CA Cert (string data) |
WECHATY_PUPPET_SERVICE_TLS_SERVER_KEY |
options.tls.serverKey |
Server CA Key (string data) |
WECHATY_PUPPET_SERVICE_NO_TLS_INSECURE_SERVER |
options.tls.disable |
Set true to disable server TLS |
For Puppet Client:
Environment Variable | Options | Description |
---|---|---|
WECHATY_PUPPET_SERVICE_AUTHORITY |
options.authority |
Service discovery host, default: api.chatie.io |
WECHATY_PUPPET_SERVICE_TLS_CA_CERT |
options.caCert |
Certification Authority Root Cert, default is using Wechaty Community root cert |
WECHATY_PUPPET_SERVICE_TLS_SERVER_NAME |
options.serverName |
Server Name (mast match for SNI) |
WECHATY_PUPPET_SERVICE_NO_TLS_INSECURE_CLIENT |
options.tls.disable |
Set true to disable client TLS |
Learn more about tls at https://github.com/wechaty/puppet-service
$wechaty = \IO\Github\Wechaty\Wechaty::getInstance($token, $endPoint);
$wechaty->onScan(function($qrcode, $status, $data) {
$qr = \IO\Github\Wechaty\Util\QrcodeUtils::getQr($qrcode);
echo "$qr\n\nOnline Image: https://wechaty.github.io/qrcode/$qrcode\n";
})->onLogin(function(\IO\Github\Wechaty\User\ContactSelf $user) {
})->onMessage(function(\IO\Github\Wechaty\User\Message $message) {
$message->say("hello from PHP7.4");
})->start();
We already have Wechaty in TypeScript, It will be not too hard to translate the TypeScript(TS) to PHP because wechaty has only 3,000 lines of the TS code, they are well designed and de-coupled by the wechaty-puppet abstraction. So after we have translated those 3,000 lines of TypeScript code, we will almost be done.
As we have already a ecosystem of Wechaty in TypeScript, so we will not have to implement everything in PHP, especially, in the Feb 2020, we have finished the @chatie/grpc service abstracting module with the wechaty-puppet-service implmentation.
The following diagram shows out that we can reuse almost everything in TypeScript, and what we need to do is only the block located at the top right of the diagram: Wechaty (PHP)
.
+--------------------------+ +--------------------------+
| | | |
| Wechaty (TypeScript) | | Wechaty (PHP) |
| | | |
+--------------------------+ +--------------------------+
+-------------------------------------------------------+
| Wechaty Puppet Service |
| |
| (wechaty-puppet-service) |
+-------------------------------------------------------+
+--------------------- @chatie/grpc ----------------------+
+-------------------------------------------------------+
| Wechaty Puppet Abstract |
| |
| (wechaty-puppet) |
+-------------------------------------------------------+
+--------------------------+ +--------------------------+
| Pad Protocol | | Web Protocol |
| | | |
| wechaty-puppet-padplus | |(wechaty-puppet-puppeteer)|
+--------------------------+ +--------------------------+
+--------------------------+ +--------------------------+
| Windows Protocol | | Mac Protocol |
| | | |
| (wechaty-puppet-windows) | | (wechaty-puppet-macpro) |
+--------------------------+ +--------------------------+
There's a 100 lines class named Image
in charge of downloading the WeChat image to different sizes.
It is a great example for demonstrating how do we translate the TypeScript to PHP in Wechaty Way:
- TypeScript: https://github.com/wechaty/wechaty/blob/master/src/user/image.ts
- PHP: https://github.com/wechaty/php-wechaty/blob/master/wechaty/IO/Github/Wechaty/User/Image.php
If you are interested in the translation and want to look at how it works, it will be a good start from reading and comparing those two Image
class files in TypeScript and PHP at the same time.
- TS: TypeScript
- SLOC: Source Lines Of Code
- Class Wechaty
- TS SLOC(1160): https://github.com/wechaty/wechaty/blob/master/src/wechaty.ts
- Code
- Unit Tests
- Documentation
- Class Contact
- TS SLOC(804): https://github.com/wechaty/wechaty/blob/master/src/user/contact.ts
- Code
- Unit Tests
- Documentation
- Class ContactSelf
- TS SLOC(199): https://github.com/wechaty/wechaty/blob/master/src/user/contact-self.ts
- Code
- Unit Tests
- Documentation
- Class Message
- TS SLOC(1054): https://github.com/wechaty/wechaty/blob/master/src/user/message.ts
- Code
- Unit Tests
- Documentation
- Class Room
- TS SLOC(1194): https://github.com/wechaty/wechaty/blob/master/src/user/room.ts
- Code
- Unit Tests
- Documentation
- Class Image
- TS SLOC(60): https://github.com/wechaty/wechaty/blob/master/src/user/image.ts
- Code
- Unit Tests
- Documentation
- Class Accessory
- TS SLOC(179): https://github.com/wechaty/wechaty/blob/master/src/accessory.ts
- Code
- Unit Tests
- Documentation
- Class Config
- TS SLOC(187): https://github.com/wechaty/wechaty/blob/master/src/config.ts
- Code
- Unit Tests
- Documentation
- Class Favorite
- TS SLOC(52): https://github.com/wechaty/wechaty/blob/master/src/user/favorite.ts
- Code
- Unit Tests
- Documentation
- Class Friendship
- TS SLOC(417): https://github.com/wechaty/wechaty/blob/master/src/user/friendship.ts
- Code
- Unit Tests
- Documentation
- Class MiniProgram
- TS SLOC(70): https://github.com/wechaty/wechaty/blob/master/src/user/mini-program.ts
- Code
- Unit Tests
- Documentation
- Class RoomInvitation
- TS SLOC(317): https://github.com/wechaty/wechaty/blob/master/src/user/room-invitation.ts
- Code
- Unit Tests
- Documentation
- Class Tag
- TS SLOC(190): https://github.com/wechaty/wechaty/blob/master/src/user/tag.ts
- Code
- Unit Tests
- Documentation
- Class UrlLink
- TS SLOC(107): https://github.com/wechaty/wechaty/blob/master/src/user/url-link.ts
- Code
- Unit Tests
- Documentation
- Class FileBox
- TS SLOC(638): https://github.com/huan/file-box/blob/master/src/file-box.ts
- Code
- Unit Tests
- Documentation
- Class MemoryCard
- TS SLOC(376): https://github.com/huan/memory-card/blob/master/src/memory-card.ts
- Code
- Unit Tests
- Documentation
- Class WechatyPuppet
- TS SLOC(1115): https://github.com/wechaty/wechaty-puppet/blob/master/src/puppet.ts
- Code
- Unit Tests
- Documentation
- Class WechatyPuppetService
- TS SLOC(909): https://github.com/wechaty/wechaty-puppet-service/blob/master/src/client/puppet-service.ts
- Code
- Unit Tests
- Documentation
WIP...
docker build -t php-wechaty:v1 .
docker run -ti --volume="$(pwd)":/bot --rm php-wechaty:v1 docker/ding-dong-bot.php
- PHP 7.4+
pecl install grpc
pecl install protobuf
pecl install yac
# php make sure is 7.4+
sudo yum install php-pecl-grpc
sudo yum install php-pecl-protobuf
sudo yum install php-pecl-yac
sudo yum install php-xml
# php74
sudo yum install php74-php-pecl-grpc
sudo yum install php74-php-pecl-protobuf
sudo yum install php74-php-pecl-yac
sudo yum install php74-php-xml
# php[x]
sudo yum install php[x]-php-pecl-grpc
sudo yum install php[x]-php-pecl-protobuf
sudo yum install php[x]-php-pecl-yac
sudo yum install php[x]-php-xml
yac.enable=1
yac.enable_cli=1
composer config repo.packagist composer https://mirrors.aliyun.com/composer/
# https://packagist.org/packages/wechaty/php-wechaty
composer require wechaty/php-wechaty
php examples/bot.php
- Project created.
- Welcome our first PHP Wechaty contributor:
- Chunsheng Zhang (张春生) https://github.com/zhangchunsheng (https://github.com/wechaty/php-wechaty)
- Wechaty - Conversatioanl AI Chatot SDK for Wechaty Individual Accounts (TypeScript)
- Python Wechaty - Python WeChaty Conversational AI Chatbot SDK for Wechat Individual Accounts (Python)
- Go Wechaty - Go WeChaty Conversational AI Chatbot SDK for Wechat Individual Accounts (Go)
- Java Wechaty - Java WeChaty Conversational AI Chatbot SDK for Wechat Individual Accounts (Java)
- Scala Wechaty - Scala WeChaty Conversational AI Chatbot SDK for WechatyIndividual Accounts (Scala)
- PHP Wechaty - PHP WeChaty Conversational AI Chatbot SDK for WechatyIndividual Accounts (PHP)
- .NET(C#) Wechaty - .NET(C#) WeChaty Conversational AI Chatbot SDK for WechatyIndividual Accounts (.NET/C#)
[![Wechaty in PHP](https://img.shields.io/badge/Wechaty-PHP-7de)](https://github.com/wechaty/php-wechaty)
- @zhangchunsheng - Chunsheng Zhang (张春生)
- @zhangchunsheng - Chunsheng Zhang (张春生)
- Code & Docs © 2020 Wechaty Contributors https://github.com/wechaty
- Code released under the Apache-2.0 License
- Docs released under Creative Commons