定制 impeto/mogreet-php 二次开发

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

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

impeto/mogreet-php

Composer 安装命令:

composer require impeto/mogreet-php

包简介

Mogreet PHP Library

README 文档

README

This is a drastically modified version of the official Mogreet PHP repo, which you can find here. Please use that one if you are running PHP < 5.5 or if you, for some reason, do not use namespaces in your app.

Introduction

This is a PHP wrapper for the Mogreet API.

Installation

The installation is done via Composer:

     composer require impeto/mogreet-php

Or by cloning this repo:

git clone https://github.com/impeto/mogreet-php.git

Usage examples

Create a client

There are two ways to create a client. One is by providing the Mogreet clientId and token to the Mogreet\Client class' constructor, like this:

<?php
...
use Mogreet\Client;
...

     $clientId = 'xxxxx'; // Your Client ID from https://developer.mogreet.com/dashboard
     $token = 'xxxxx'; // Your token from https://developer.mogreet.com/dashboard
     $client = new Client( $clientId, $token);

The other way is by storing the clientId and token in two environment variables named MOGREET_CLIENT_ID and MOGREET_TOKEN respectively. Instantiating the Mogreet class with an empty constructor will instantiate the class with these values:

     $client = new Mogreet\Client();

Laravel Support

The package includes a Laravel ServiceProvider as well as a Facade for easy access to functionality in Laravel style. All you have to do is to register the Service Provider and the Facade with the Laravel App in config/app.php file:

     ...
     'providers' => [
          ...
          Mogreet\Laravel\MogreetServiceProvider::class,
          ...
     ],
     ...
     'aliases' => [
          ...
          'Mogreet' => Mogreet\Laravel\MogreetFacade::class,
          ...
     ]

Then you can use it like this:

     ...
     $result = Mogreet::system()->ping();
     //or
     $result = app('mogreet')->system()->ping();
     //or
     $result = app(Mogreet\Client::class)->system()->ping();
     return $result->status;

Configuration

When resolving the Mogreet\Client object form the Laravel IoC, using the Mogreet facade, app('mogreet') or app(Mogreet\Client::class), the MogreetServiceProvider will check for the existence of a config/mogreet.php file. If the file exists, it will use Laravel's Config mechanism to obtain the client_id and token values, like this: Config::get( 'mogreet.client_id') and Config::get( 'mogreet.token'). So, what you have to do is create a config/mogreet.php file with the following contents:

<?php
return [
     'client_id' => 'your client id here',
     'token' => 'your token here'
];

If the config file does not exist, then MogreetServiceProvider will instantiate the Client class with an empty constructor, which means that the client_id and token values will be obtained from the environment variables, as explained above. In order to use this package in Laravel style, you must at the least create the environment variables MOGREET_CLIENT_ID and MOGREET_TOKEN; otherwise you will have to instantiate the Client class manually as if you were using vanilla PHP.

Ping

$response = $client->system()->ping();
echo $response->message;

Send an SMS to one recipient

$response = $client->transaction()->send(array(
    'campaign_id' => 'xxxxx', // Your SMS campaign ID from https://developer.mogreet.com/dashboard
    'to' => '9999999999',
    'message' => 'Hello form Mogreet API!'
));
echo $response->messageId;

Send an MMS to one recipient

$response = $client->transaction()->send(array(
    'campaign_id' => 'xxxxx', // Your MMS campaign ID from https://developer.mogreet.com/dashboard
    'to' => '9999999999',
    'message' => 'This is super easy!',
    'content_url' => 'https://wp-uploads.mogreet.com/wp-uploads/2013/02/API-Beer-sticker-300dpi-1024x1024.jpg'
));
echo $response->messageId;

Upload a media file

$response = $client->media()->upload(array(
    'type' => 'image',
    'name' => 'mogreet logo',
    'file' => '/path/to/image/mogreet.png',
    // to ingest a file already online, use: 'url' => 'https://wp-uploads.mogreet.com/wp-uploads/2013/02/API-Beer-sticker-300dpi-1024x1024.jpg'
));
echo $response->media->smartUrl;
echo '<br/>';
echo $response->media->contentId;

List all medias

$response = $client->media()->listAll();
foreach($response->mediaList as $media) {
    echo $media->contentId . ' => ' . $media->name . ' ' . $media->smartUrl . '<br />';
}

Notes

With the Response object, you can print the plain JSON response of the API call (echo $response), or access directly a field (e.g: $response->message).

Due to the keyword restriction on 'list' and the existing function 'empty()' in PHP, I changed the mappings of the following API calls:

  • $client->*->listAll() maps to the method list
  • $client->list->pruneAll() maps to 'list.empty'

Full Documentation

The full documentation for the Mogreet API is available here

Prerequisites

  • PHP >= 5.5
  • The PHP JSON extension

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-04-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固