beedelivery / client-php-api-wa-me
用于与api-wa.me通信的PHP类
v1.0.1
2024-01-22 19:03 UTC
Requires
- php: ^7.2|^8.1
- ext-curl: *
README
生成实例密钥
访问:api-wa.me
通过composer安装
composer require beedelivery/client-php-api-wa-me
示例
use Api\Wame\WhatsApp; include_once 'vendor/autoload.php'; $whatsapp = new WhatsApp( ["server" => "API server", "key" => "Your Key Instance"] );
获取webhook
$whatsapp->constructWebhook(); $whatsapp->from->remoteJid; // number that sent message $whatsapp->from->messageType; // video | text | audio| image | sticker | document| reaction | liveLocation | $whatsapp->from->msgId; $whatsapp->from->pushName; $whatsapp->from->text;
示例
if ($whatsapp->from->messageType === "text" && $whatsapp->from->text === "Hi") { $whatsapp->sendText($whatsapp->from->remoteJid, "Hello!"); }
获取QrCode HTML
echo $whatsapp->getQrCodeHTML();
获取QrCode Base64
echo $whatsapp->getQrCodeBase64();
信息实例
echo $whatsapp->inforInstance();
更新Webhook
$body = [ "allowWebhook" => false, "webhookMessage" => "", "webhookGroup" => "", "webhookConnection" => "", "webhookQrCode" => "", "webhookMessageFromMe"=>"", "webhookHistory"=>"" ]; echo $whatsapp->updateWebhook($body);
注销
echo $whatsapp->logout();
操作
获取联系人列表
echo $whatsapp->listContacts();
获取个人头像
echo $whatsapp->profilePic('556696852025');
更新个人昵称
echo $whatsapp->updateProfileName('Raphael Serafim');
更新个人和群组头像
$url =''; // url image $id ='556696852025'; // if it's a group, use full id ex: 123456789@g.us echo $whatsapp->updateProfilePicture($id, $url);
已读回执
$MsgId =''; $to ='556696852025'; // if it's a group, use full id ex: 123456789@g.us echo $whatsapp->readReceipt($to, $MsgId);
下载媒体
$body = [ "messageKeys" => [ "mediaKey" => "", "directPath" => "", "url" => "", "messageType" => "" ] ]; echo $whatsapp->downloadMediaMessage($body);
发送消息
发送存在状态
$to = '556696852025'; // if it's a group, use full id ex: 123456789@g.us $status = 'composing'; // unavailable | available | composing | recording | paused echo $whatsapp->sendPresence($to, $status);
发送文本
$to = '556696852025'; // if it's a group, use full id ex: 123456789@g.us $text = 'Hi'; echo $whatsapp->sendText($to, $text);
发送音频
$to = '556696852025'; // if it's a group, use full id ex: 123456789@g.us $url = ''; // your MP3 or OGG audio URL $ptt = true; echo $whatsapp->sendAudio($to, $url, $ptt );
发送媒体
$to = '556696852025'; // if it's a group, use full id ex: 123456789@g.us $url = ''; $type = 'image'; // image | video | audio | document $caption = 'Hi'; echo $whatsapp->sendMedia($to, $url, $type, $caption);
发送按钮
$body = [ "to" => "556696852025", "data" => [ "text" => "Recebeu ?", "buttons" => [ [ "title" => "Sim", "id" => "1" ], [ "title" => "Não", "id" => "2" ] ], "footerText" => "Escolha uma opção" ] ]; echo $whatsapp->sendButton($body);
发送模板按钮
$body = [ "to" => "556696852025", "data" => [ "text" => "Finalizar a compra", "buttons" => [ [ "type" => "urlButton", // replyButton | urlButton | callButton "title" => "Pagar", "payload" => "https://api-wa.me" ] ], "footerText" => "Visite o site para finalizar" ] ]; echo $whatsapp->sendTemplateButtons($body);
发送列表
$body = [ "messageData" => [ "to" => "556696852025", "buttonText" => "Menu", "text" => "Esse nosso menu", "title" => "Menu", "description" => "veja nosso menu", "sections" => [ [ "title" => "Menu 01", "rows" => [ [ "title" => "Opção 01", "description" => "essa é uma opção", "rowId" => "1" ], [ "title" => "Opção 02", "description" => "essa é outra opção", "rowId" => "2" ] ] ] ], "listType" => 0 ] ]; echo $whatsapp->sendList($body);
发送联系人
$to = '556696852025'; // if it's a group, use full id ex: 123456789@g.us $name = 'CACHE SISTEMAS'; $number = '+556696883327'; echo $whatsapp->sendContact($to, $name, $number);
发送位置
$to = '556696852025'; // if it's a group, use full id ex: 123456789@g.us $lat = 35.000; $lon = 20.000; $address = 'Rua do fulando'; echo $whatsapp->sendLocation($to, $lat, $lon, $address);
发送反应
$to = '556696852025'; // if it's a group, use full id ex: 123456789@g.us $text = '😘'; $msgId = ''; echo $whatsapp->sendReaction($to, $text, $msgId);
群组
获取群组列表
echo $whatsapp->listGroup();
获取群组信息
$group_id = '123456789@g.us'; echo $whatsapp->inforGroup($group_id);
获取群组邀请码
$group_id = '123456789@g.us'; echo $whatsapp->groupInviteCode($group_id);
创建群组
$name = 'API PHP WhatsApp'; $participants = ['556696852025']; echo $whatsapp->createGroup($name, $participants);
添加群组成员
$group_id = '123456789@g.us'; $participants = ['556696852025']; echo $whatsapp->addParticipantsGroup($group_id, $participants);
提升群组成员为管理员
$group_id = '123456789@g.us'; $participants = ['556696852025']; echo $whatsapp->promoteParticipantsGroup($group_id, $participants);
降级群组成员
$group_id = '123456789@g.us'; $participants = ['556696852025']; echo $whatsapp->demoteParticipantsGroup($group_id, $participants);
设置谁可以发送群组消息
$group_id = '123456789@g.us'; // true = Admin; false= All echo $whatsapp->setWhoCanSendMessageGroup($group_id, true);
设置谁可以更改群组设置
$group_id = '123456789@g.us'; // true = Admin; false= All echo $whatsapp->setWhoCanChangeSettingsGroup($group_id, true);
移除群组成员
$group_id = '123456789@g.us'; $participants = ['556696852025']; echo $whatsapp->removeParticipantsGroup($group_id, $participants);
退出群组
$group_id = '123456789@g.us'; echo $whatsapp->leaveGroup($group_id);