使用轻识AI智能搜索

轻识AI

SDK

共 4962字,需浏览 10分钟

 ·

2023-04-25 14:26

Java

install

Use Maven ,get from Maven repository .

Add Maven dependencies to your project with the following code:

<dependency>
    <groupId>com.apistd.uni</groupId>
    <artifactId>uni-sdk</artifactId>
    <version>0.0.4</version>
</dependency>

or use Gradle:

implementation "com.apistd.uni:uni-sdk:0.0.4"

example

The following example shows how to use Uni Go SDK to quickly call services.(

send message

import com.apistd.uni.Uni;
import com.apistd.uni.UniException;
import com.apistd.uni.UniResponse;
import com.apistd.uni.sms.UniSMS;
import com.apistd.uni.sms.UniMessage;

import java.util.HashMap;
import java.util.Map;

public class Example {
    public static String ACCESS_KEY_ID = "your access key id";
    private static String ACCESS_KEY_SECRET = "your access key secret";

    public static void main(String[] args) {
        // init
        Uni.init(ACCESS_KEY_ID, ACCESS_KEY_SECRET); // if use simple mode,only input first parameter.

        // use custom parameter
        Map templateData = new HashMap();
        templateData.put("code", "6666");

        // build message
        UniMessage message = UniSMS.buildMessage()
            .setTo("your phone number")
            .setSignature("UniSMS")
            .setTemplateId("login_tmpl")
            .setTemplateData(templateData);

        // send message
        try {
            UniResponse res = message.send();
            System.out.println(res);
        } catch (UniException e) {
            System.out.println("Error: " + e);
            System.out.println("RequestId: " + e.requestId);
        }
    }
}


Go

install

Uni Go SDK supply Go Module, you can get from Github.

Add uni-go-sdk as a dependency in your project:

go get github.com/apistd/uni-go-sdk

example

The following example shows how to use Uni Go SDK to quickly call services.(

send message

package main

import (
    "fmt"
    unisms "github.com/apistd/uni-go-sdk/sms"
)

func main() {
    // init
    client := unisms.NewClient("your access key id", "your access key secret") // if use simple mode,only input first parameter.

    // build message
    message := unisms.BuildMessage()
    message.SetTo("your phone number")
    message.SetSignature("UniSMS")
    message.SetTemplateId("login_tmpl")
    message.SetTemplateData(map[string]string {"code": "6666"}) // use custom parameter

    // send message
    res, err := client.Send(message)
    if (err != nil) {
        fmt.Println(err)
        return
    }
    fmt.Println(res)
}


Node.js

install

use npm ,get from npm repository .

Add unisms as a dependency in the project:

npm i unisms

or use Yarn:

yarn add unisms

example

The following example shows how to use Uni Go SDK to quickly call services.(

send message

import UniSMS from 'unisms'

// init
const client = new UniSMS({
  accessKeyId: 'your access key id',
  accessKeySecret: 'your access key secret',  // if use simple mode,only input first parameter
})

// send message
client.send({
  to: 'your phone number',
  signature: 'UniSMS',
  templateId: 'login_tmpl',
  // use custom parameter
  templateData: {
    code: 8888,
  },
})
  .then(ret => {
    console.info('Result:', ret)
  })
  .catch(e => {
    console.error(e)
  })

If the following error is encountered:

SyntaxError: Cannot use import statement outside a module

or :

TypeError: UniSMS is not a constructor

You can adjust the references in the following ways:

// import UniSMS from 'unisms'
const UniSMS = require('unisms').default


Python SDK

install

Hosted at PyPI ,Get from PyPI repository .

Use pip to add unisms as a dependency in the project:

pip install unisms

example

The following example shows how to use Uni Go SDK to quickly call services.(

send message

from unisdk.sms import UniSMS
from unisdk.exception import UniException

# init
client = UniSMS("your access key id", "your access key secret") # if use simple mode,only input first parameter.

try:
  # send message
  res = client.send({
    "to": "your phone number",
    "signature": "UniSMS",
    "templateId": "login_tmpl",
    # use custom parameter
    "templateData": {
      "code": 7777
    }
  })
  print(res.data)
except UniException as e:
  print(e)


PHP

install

Hosted at Packagist ,Get from Packagist repository .

Use Composer to add apistd/uni-sdk to your project as a dependency:

composer require apistd/uni-sdk

example

The following example shows how to use Uni Go SDK to quickly call services.(

send message

use Uni\Common\UniException;
use Uni\SMS\UniSMS;

// init
$client = new UniSMS([
  'accessKeyId' => 'your access key id',
  'accessKeySecret' => 'your access key secret' // if use simple mode,only input first parameter.
]);

// send message
try {
  $resp = $client->send([
    'to' => 'your phone number',
    'signature' => 'UniSMS',
    'templateId' => 'login_tmpl',
    // use custom parameter
    'templateData' => [
      'code' => 7777
    ]
  ]);
  var_dump($resp->data);
} catch (UniException $e) {
  print_r($e);
}





浏览 9
点赞
评论
收藏
分享

手机扫一扫分享

分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

分享
举报