supreme/usmsgh-api-sdk 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

supreme/usmsgh-api-sdk

Composer 安装命令:

composer require supreme/usmsgh-api-sdk

包简介

PHP SDK for the Urhitech Bulk SMS API

README 文档

README

The Urhitech SMS PHP SDK provides a suitable approach to the USMSGH API from applications written in PHP. It includes pre-defined set of classes and functions for API resource that initialize themeselves from API responses.

The library provides other features. For Example:

  1. Easy configuration path for fast setup and use
  2. Helpers for pagination.

Latest Version on Packagist Software License Total Downloads PHP Version Laravel Version

This package makes it easy to send notifications using USMSGH with Laravel 8.x, 9.x, 10.x, and 11.x

You can sign up for a USMSGH account at usmsgh.com

Contents

Prerequisites

PHP 8.0 or later

Installation

Via Composer

$ composer require usmsgh/usmsgh-api-sdk

Via Git Bash

git clone git@github.com:urhitech/usmsgh-api-sdk.git

Documentation

Please see https://usmsgh.com/developer/ for up-to-date documentation

Usage

Step 1:

If you install the Urhitech SMS PHP SDK via Git Clone then load the Urhitech SMS PHP API class file and use namespace.

require_once '/path/to/src/Usms.php';
use Urhitech\Usmsgh\Usms;

If you install Urhitech SMS PHP SDK via Composer the Require the autoload.php file in the index.php of your project or whatever file you need to use Urhitech SMS PHP API classes.

require __DIR__ . '/vendor/autoload.php';
use Urhitech\Usmsgh\Usms;

The Urhitech SMS PHP SDK endpoints are RESTful, and consume and return JSON. All Http endpoints requires an API Key in the request header.

For more information on how to get an API Key visit here to copy or generate new key for authorization.

HTTP ENDPOINTS

For Laravel Usage:

Setting up the Usmsgh .env

Add the following code to you .env:

USMSGH_ENDPOINT=
USMSGH_API_TOKEN=
USMSGH_SENDER=
#USMSGH_UNIVERSAL_TO=

Setting up the Usmsgh service

Add the following code to you config/services.php:

// config/services.php
...
'usmsgh' => [
    'sender_endpoint' => env('USMSGH_ENDPOINT', 'https://webapp.usmsgh.com/api/sms/send'),
    'api_token' => env('USMSGH_API_TOKEN'),
    'sender_id' => env('USMSGH_SENDER'),
    'universal_to' => env('USMSGH_UNIVERSAL_TO'),
],
...

Usage

Now you can use the channel in your via() method inside the notification:

use Urhitech\Usmsgh\UsmsChannel;
use Urhitech\Usmsgh\UsmsMessage;
use Illuminate\Notifications\Notification;

class ProjectCreated extends Notification
{
    public function via($notifiable)
    {
        return [UsmsChannel::class]; // or 'usmsgh'
    }

    public function toUsms($notifiable)
    {
        return new UsmsMessage('Content');
    }
}

In order to let your Notification know which phone number to use, add the routeNotificationForUsmsgh method to your Notifiable model.

This method needs to return a phone number.

public function routeNotificationForUsmsgh(Notification $notification)
{
    return $this->phone_number;
}

Local development

When developing an application that sends SMS, you probably don't want to actually send SMS to live phone numbers. You may set a universal recipient of all SMS sent. This can be done by the USMSGH_UNIVERSAL_TO environment variable or the universal_to option.

Available Message methods

  • content(string $content): Accepts a string value for the sms content.
  • sender(string $sender_id): Accepts a string value for the sender name.
  • campaign(string $campaign): Accepts a string value for the sms campaign name.
  • sendAt(\DateTimeInterface|string $sendAt): Accepts a DateTimeInterface or string for the sms due date.
  • parameters(array $parameters): Accepts an array for the sms parameters.

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Step 2:

Instantiate the Urhitech SMS PHP API

$client = new Urhitech\Usmsgh\Usms;

Send SMS

$api_key = "Enter Your API Key here";

$url = "https://webapp.usmsgh.com/api/sms/send";

$recipients = "233500000000,233540000000";
$message = "Hello world";
$senderid = "Enter your approved sender ID here";

$response = $client->send_sms($url, $api_key, $senderid, $recipients, $message);

Check SMS Credit Balance

$api_key = "Enter Your API TOKEN here";

$url = "https://webapp.usmsgh.com/api/balance";

$get_credit_balance = $client->check_balance($url, $api_key);

View Profile

$api_key = "Enter Your API Key here";

$url = "https://webapp.usmsgh.com/api/me";

$get_profile = $client->profile($url, $api_key);

Security

If you discover any security related issues, please email supremetechnology2023@gmail.com instead of using the issue tracker.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

supreme/usmsgh-api-sdk 适用场景与选型建议

supreme/usmsgh-api-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 01 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 supreme/usmsgh-api-sdk 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-01-19