定制 positus/positus-api-php-client 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

positus/positus-api-php-client

Composer 安装命令:

composer require positus/positus-api-php-client

包简介

Client library for Positus APIs

README 文档

README

  • PHP 7.3+

Installing

Use Composer to install it:

composer require positus/positus-api-php-client

If you use Laravel, we provide a wrapper.

Instantiating

use Positus\Client;

$client = new Client();

Authentication

If you don't have an authentication token, click here to generate one.

$client = new Client();

$client->setToken('you-api-token');

Sending Messages

The first step to be able to send messages is to specify the ID number of origin:

$number = $client->number('your-number-id');

Then send the message and wait for a response.

If you want to test a Sandbox you can pass a second argument when calling the number method as true:

$number = $client->number('sandbox-number-id', true);

If you want to send a message using data on your own, you can use:

$response = $number->sendData([
    'to' => '+5511999999999',
    'type' => 'text',
    'text' => [
        'body' => 'Hi!'
    ]
]);

To check all the data that can be sent in each type of message, check the WhatsApp Business documentation.

If you prefer, we provide ready methods for each type of message.

Text

$response = $number->sendText('+5511999999999', 'Your message');

Template

$response = $number->sendTemplate('+5511999999999', 'namespace', 'name', 'languageCode', [
    "type" => "body",
    "parameters" => [
        [
            "type" => "text",
            "text" => "Param 1"
        ],
        ...
    ]
]);

Please check the documentation related to templates in the WhatsApp Business documentation.

Contacts

$response = $number->sendContacts('+5511999999999', [
    [
        'name' => [
            "formatted_name" => "John Doe"
        ],
        'phones' => [
            'phone' => '+5511888888888',
            'type' => 'CELL'
        ]
    ]
]);

Please check the documentation related to contacts in the WhatsApp Business documentation.

Location

$response = $number->sendLocation('+5511999999999', '-23.553885', '-46.662819', 'Robbu - Atendimento digital inteligente', 'Av. Angélica, 2530 - Bela Vista, São Paulo - SP, 01228-200');

Image

$response = $number->sendImage('+5511999999999', 'https://example.com/image.jpg', 'Random Image');

Document

$response = $number->sendDocument('+5511999999999', 'https://example.com/document.pdf', 'Random Document');

Video

$response = $number->sendVideo('+5511999999999', 'https://example.com/video.mp4', 'Random Video');

Audio

$response = $number->sendAudio('+5511999999999', 'https://example.com/audio.mp3');

Receiving media

To download a media, use the following method:

$response = $number->getMedia('media-id');

Responses

After any call you can check if everything went well and receive the data using the following methods:

if ($response->success()) {
    echo 'Message with Id ' . $response->json()->messages[0]->id . ' sent successfully';
}

If everything goes correctly you will receive an answer like this:

{
    "messages": [
        {
            "id": "gBEGVUOWQWWQAgnFOaNl67sTDIE"
        }
    ],
    "message": "The message was successfully sent"
}

If something goes wrong, you will receive a message detailing the errors:

{
    "errors": [
        {
            "code": 1008,
            "title": "Required parameter is missing",
            "details": "Parameter 'body' is mandatory for type 'text'"
        }
    ],
    "message": "Unfortunately we were not able to send your message"
}

Please check all possible errors that the api may return in the WhatsApp Business documentation.

Feel free to create a pull request or open a support ticket in Positus Studio if you have or find any problems.

You can check if it failed:

if ($response->error()) {
    echo 'Something went wrong';
}

If you only need the status code:

$response->status();

You can get the answer from api as a string:

$response->body();

Or if you prefer as JSON:

$response->json();

Or if you prefer as object:

$response->object();

You can get a header:

$response->header('Content-Type');

Or you can get all headers:

$response->headers();

positus/positus-api-php-client 适用场景与选型建议

positus/positus-api-php-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.92k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2020 年 07 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「positus」 「positus-api-php-client」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 positus/positus-api-php-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 positus/positus-api-php-client 我们能提供哪些服务?
定制开发 / 二次开发

基于 positus/positus-api-php-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

与 positus/positus-api-php-client 相关的其它包

同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:

统计信息

  • 总下载量: 3.92k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 4
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-07-16