### Install and Configure YunPian SDK Source: https://github.com/yunpian/sms/blob/master/thirdparty/nodejs/yunpian-sdk/README.md Install the package via npm and initialize the configuration object. ```bash npm install yunpian-sdk --save ``` ```js var options = { apikey: 'xxxxxxx' }; ``` -------------------------------- ### Install YunPian SDK Source: https://github.com/yunpian/sms/blob/master/thirdparty/nodejs/README.md Install the package via npm. ```bash npm install yunpian-sdk --save ``` -------------------------------- ### Account API Usage Source: https://github.com/yunpian/sms/blob/master/thirdparty/nodejs/yunpian-sdk/README.md Example of fetching and updating user account information using the USER API. ```js import {USER} from 'yunpian-sdk'; const user = new USER({ apikey: 'xxxx' }); (async() => { const user = await user.get(); // xxxx const result = await user.set({ emergency_contact: 'Willin', emergency_mobile: '1xxxxxxxxxx' }); // xxxx })(); ``` -------------------------------- ### Co/Generator Wrapper Source: https://github.com/yunpian/sms/blob/master/thirdparty/nodejs/yunpian-sms-client/README.md Example of wrapping the API call using co or ES6+ generators. ```javascript return co(function *() { const path = '/v2/sms/get_reply.json'; let data = { start_time: '2016-08-11 00:00:00', end_time: '2017-08-11 00:00:00', page_num: 1, //页码,默认1,必填 page_size: 20 //页大小,最大允许100,必填, /*mobile:13xxxxxx*///填写时只查该手机号的回复,不填时查所有的回复 ,可选 }; return provider.getCustomReqSmsAPI(data, path); }); ``` -------------------------------- ### Get SMS Reply Record Source: https://github.com/yunpian/sms/blob/master/thirdparty/nodejs/yunpian-sms-client/README.md Retrieve records of SMS replies received. ```javascript provider.getSmsReplyRecord({ start_time: '2016-08-11 00:00:00', end_time: '2017-08-11 00:00:00', page_num:1, //页码,默认1,必填 page_size:20 //页大小,最大允许100,必填, /*mobile:13xxxxxx*///填写时只查该手机号的回复,不填时查所有的回复 ,可选 }).then(function (res) { if(res) { console.log(res); } }).catch(function (e) { console.log(e); }); ``` -------------------------------- ### Get SMS Status Report Source: https://github.com/yunpian/sms/blob/master/thirdparty/nodejs/yunpian-sms-client/README.md Retrieve the status report for sent SMS messages. ```javascript provider.getSmsStatusReport({page_size: 10}).then(function (report) { if (report) { console.log(report); } }).catch(function (err) { console.log(err); }); ``` -------------------------------- ### Get SMS Send Record Source: https://github.com/yunpian/sms/blob/master/thirdparty/nodejs/yunpian-sms-client/README.md Retrieve historical records of sent SMS messages. ```javascript provider.getSmsSendRecord({start_time: '2016-01-02 00:00:00', end_time: '2016-06-23 12:00:00'}).then(function (record) { if (record) { console.log(record); } }).catch(function (err) { console.log(err); }); ``` -------------------------------- ### Initialize and Use User API Source: https://github.com/yunpian/sms/blob/master/thirdparty/nodejs/yunpian-sdk/README.md Demonstrates initializing the USER module and performing account operations using ES7 and ES5 syntax. ```js import {USER} from 'yunpian-sdk'; const user = new USER({ apikey: 'xxxx' }); // Within Async Func (async() => { const result = await user.set({ emergency_contact: 'Willin', emergency_mobile: '1xxxxxxxxxx' }); // xxxx }); ``` ```js var YUNPIAN = require('yunpian-sdk'); // 加载全部方法 var user = new YUNPIAN.USER({ apikey: 'xxxx' }); // 或加载某些方法 var user = new YUNPIAN.USER({ apikey: 'xxxx' }, ['get', 'set']); // 或加载某个方法 var user = new YUNPIAN.USER({ apikey: 'xxxx' }, 'get'); user.set({ emergency_contact: 'Willin', emergency_mobile: '1xxxxxxxxxx' }).then(function(result){ // xxxx }); ``` -------------------------------- ### Initializing the Yunpian API Source: https://github.com/yunpian/sms/blob/master/thirdparty/go/README.md Create a new API instance using your unique Yunpian API key. ```go api := NewYunpianAPI("你的apikey") ``` -------------------------------- ### Initialize and Use User API (ES7) Source: https://github.com/yunpian/sms/blob/master/thirdparty/nodejs/README.md Initialize and use the User API using ES7 async/await syntax. ```javascript import {USER} from 'yunpian-sdk'; const user = new USER({ apikey: 'xxxx' }); // Within Async Func (async() => { const result = await user.set({ emergency_contact: 'Willin', emergency_mobile: '1xxxxxxxxxx' }); // xxxx }); ``` ```javascript import {USER} from 'yunpian-sdk'; const user = new USER({ apikey: 'xxxx' }); (async() => { const user = await user.get(); // xxxx const result = await user.set({ emergency_contact: 'Willin', emergency_mobile: '1xxxxxxxxxx' }); // xxxx })(); ``` -------------------------------- ### Initialize and Use User API (ES5) Source: https://github.com/yunpian/sms/blob/master/thirdparty/nodejs/README.md Initialize the User API in ES5, with options to load all or specific methods. ```javascript var YUNPIAN = require('yunpian-sdk'); // 加载全部方法 var user = new YUNPIAN.USER({ apikey: 'xxxx' }); // 或加载某些方法 var user = new YUNPIAN.USER({ apikey: 'xxxx' }, ['get', 'set']); // 或加载某个方法 var user = new YUNPIAN.USER({ apikey: 'xxxx' }, 'get'); user.set({ emergency_contact: 'Willin', emergency_mobile: '1xxxxxxxxxx' }).then(function(result){ // xxxx }); ``` -------------------------------- ### Initialize and Use Yunpian SMS Managers Source: https://github.com/yunpian/sms/blob/master/thirdparty/csharp/README.md Demonstrates how to instantiate AccountManager and SmsManager using a configuration object and perform basic operations. ```csharp var _accountManager = new AccountManager(new DefaultYunPianConfiguration { ApiKey = "your api key" }); var accountInfo = await _accountManager.GetAsync(); var smsManager = new SmsManager(new DefaultYunPianConfiguration { ApiKey = "your api key" }); var smsResult = await smsManager.Send(new BatchSendSms() { Mobile = new List { "13800138000", "13800138001" }, Text = "尊敬的用户,您的帐号于2017-01-01成功充值100元,如有疑问请联系客服。" }); ``` -------------------------------- ### Configure Dependency Injection with Autofac Source: https://github.com/yunpian/sms/blob/master/thirdparty/csharp/README.md Shows how to register Yunpian configuration and services into an Autofac container. ```csharp var builder = new ContainerBuilder(); builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly()).AsImplementedInterfaces(); builder.RegisterAssemblyTypes(Assembly.GetAssembly(typeof(IYunPianConfiguration))) .AsImplementedInterfaces(); builder.Register(c => new DefaultYunPianConfiguration { ApiKey = "your api key", }).As().SingleInstance(); IocContainer = builder.Build(); ``` -------------------------------- ### Importing the Yunpian SDK Source: https://github.com/yunpian/sms/blob/master/thirdparty/go/README.md Include this import statement in your Go project to access the Yunpian SDK functionality. ```go import ( "github.com/shesuyo/yunpian" ) ``` -------------------------------- ### USER.get() Source: https://github.com/yunpian/sms/blob/master/thirdparty/nodejs/yunpian-sdk/README.md Retrieves the current user account information. ```APIDOC ## USER.get() ### Description Fetches the account details for the authenticated user. ### Returns - **Promise** - Resolves with the user account information object. ``` -------------------------------- ### Initialize SMS Provider Source: https://github.com/yunpian/sms/blob/master/thirdparty/nodejs/yunpian-sms-client/README.md Initialize the provider using your Yunpian API key. ```javascript var smsProvider = require('yunpian-sms-client').v2; var apiKey = 'your apiKey'; var provider = smsProvider.initWithKey(apiKey); var text = '【xxxx】您的短信验证码为:23845'; var mobile = 'your mobile'; ``` -------------------------------- ### USER.set(params) Source: https://github.com/yunpian/sms/blob/master/thirdparty/nodejs/yunpian-sdk/README.md Updates the user account settings. ```APIDOC ## USER.set(params) ### Description Updates specific account settings such as emergency contact information. ### Parameters - **params** (object) - Required - An object containing the fields to update (e.g., emergency_contact, emergency_mobile). ### Returns - **Promise** - Resolves with the update result. ``` -------------------------------- ### Configure API Key Source: https://github.com/yunpian/sms/blob/master/thirdparty/nodejs/README.md Define the common options object containing the API key. ```javascript var options = { apikey: 'xxxxxxx' }; ``` -------------------------------- ### IAccountManager.GetAsync Source: https://github.com/yunpian/sms/blob/master/thirdparty/csharp/README.md Retrieves the current account information, including balance, contact details, and API version. ```APIDOC ## Task GetAsync() ### Description Retrieves the current account information from the YunPian service. ### Returns - **Account** (object) - An object containing account details such as Nick, Mobile, Email, Balance, and Emergency_Contact. ``` -------------------------------- ### Check Blacklist Words Source: https://github.com/yunpian/sms/blob/master/thirdparty/nodejs/yunpian-sms-client/README.md Check if the provided content contains any blacklisted words. ```javascript provider.isBlackWord('发票,微贷,贷款').then(function (res) { if (res) { //返回屏蔽词数组 console.log(res); } }).catch(function (e) { console.log(e); }); ``` -------------------------------- ### Custom API Request Source: https://github.com/yunpian/sms/blob/master/thirdparty/nodejs/yunpian-sms-client/README.md Perform a custom API request by specifying the path and data. ```javascript //注:若是es6使用者可以直接使用let var data = { start_time: '2016-08-11 00:00:00', end_time: '2017-08-11 00:00:00', page_num: 1, //页码,默认1,必填 page_size: 20 //页大小,最大允许100,必填, /*mobile:13xxxxxx*///填写时只查该手机号的回复,不填时查所有的回复 ,可选 }; var path = '/v2/sms/get_reply.json'; provider.getCustomReqSmsAPI(data, path).then(function (res) { if (res) { console.log(res); } }).catch(function (e) { console.log(e); }); ``` -------------------------------- ### Account API Interfaces and Models Source: https://github.com/yunpian/sms/blob/master/thirdparty/csharp/README.md Defines the IAccountManager interface and the Account data model for retrieving and updating account information. ```csharp public interface IAccountManager { /// /// 查账户信息 /// /// Task GetAsync(); /// /// 可一次修改emergency_contact、emergency_mobile和alarm_balance中的一个或多个(必须传入一个) /// /// /// Task UpdateAsync([NotNull]UpdateAccount account); } public class Account : ApiResultBase { /// /// 用户名 /// public string Nick { get; set; } /// /// 注册时间 /// public DateTime Gmt_Created { get; set; } /// /// 手机号 /// public string Mobile { get; set; } /// /// 邮箱 /// public string Email { get; set; } /// /// IP白名单,推荐使用 /// public string Ip_WhiteList { get; set; } /// /// api版本号 /// public string Api_Version { get; set; } /// /// 账户剩余条数或者剩余金额(根据账户类型) /// public string Balance { get; set; } /// /// 剩余条数或剩余金额低于该值时提醒 /// public long Alarm_Balance { get; set; } /// /// 紧急联系人 /// public string Emergency_Contact { get; set; } /// /// 紧急联系人电话 /// public string Emergency_Mobile { get; set; } } ``` -------------------------------- ### IAccountManager.UpdateAsync Source: https://github.com/yunpian/sms/blob/master/thirdparty/csharp/README.md Updates account settings such as emergency contact information or alarm balance thresholds. ```APIDOC ## Task UpdateAsync(UpdateAccount account) ### Description Updates one or more account settings including emergency_contact, emergency_mobile, or alarm_balance. ### Parameters - **account** (UpdateAccount) - Required - The object containing the fields to be updated. ``` -------------------------------- ### Sending SMS and Voice Messages Source: https://github.com/yunpian/sms/blob/master/thirdparty/go/README.md Use the SmsSend and VoiceSend methods to dispatch messages by providing the recipient's mobile number and the message content. ```go api.SmsSend(SMSSendInfo{Mobile: "13250061802", Text: "【垣创科技】您的验证码是970702"}) ``` ```go api.VoiceSend(VoiceSendInfo{Mobile: "13250061802", Text: "970702"}) ``` -------------------------------- ### SMS.singleSend(params) Source: https://github.com/yunpian/sms/blob/master/thirdparty/nodejs/yunpian-sdk/README.md Sends a single SMS message. ```APIDOC ## SMS.singleSend(params) ### Description Sends a single SMS message to a specified mobile number. ### Parameters - **params** (object) - Required - Contains 'mobile' (string) and 'text' (string) fields. ### Returns - **Promise** - Resolves with the API response indicating the status of the SMS delivery. ``` -------------------------------- ### Send Single SMS Source: https://github.com/yunpian/sms/blob/master/thirdparty/nodejs/yunpian-sms-client/README.md Send a single SMS message using the provider. ```javascript provider.sendSingleSms({ mobile: mobile, text: text, uid: '234'//可选,请参见官方文档说明 }).then(function (result) { if (result) { console.log(result); } }).catch(function (err) { console.log(err); }); //或者分步写效果是一样,后续的示例不再重复说明 var promise = provider.sendSingleSms({ mobile: mobile, text: text, uid: '234'//可选,请参见官方文档说明 }); promise.then(function(result){ // }); promise.catch(function(err){ // }) ``` -------------------------------- ### Send SMS (ES7) Source: https://github.com/yunpian/sms/blob/master/thirdparty/nodejs/README.md Send a single SMS message using the SMS API with async/await. ```javascript import {SMS} from 'yunpian-sdk'; const sms = new SMS({ apikey: 'xxxx' }); (async() => { console.log(await sms.singleSend({ mobile: 'xxxx', text: '【xxxx】您的验证码是:123456 (验证码10分钟内有效),请勿将验证码泄露给其他人。如非本人操作,请忽略本短信。' })); })(); ``` -------------------------------- ### isBlackWord Source: https://github.com/yunpian/sms/blob/master/thirdparty/nodejs/yunpian-sms-client/README.md Checks if the provided text contains any blacklisted words. ```APIDOC ## provider.isBlackWord(text) ### Description Checks the provided text against the platform's blacklist. ### Parameters - **text** (string) - Required - The text content to check. ``` -------------------------------- ### phone(number, [countryCode]) Source: https://github.com/yunpian/sms/blob/master/thirdparty/nodejs/yunpian-sdk/README.md Validates the format of a phone number. It supports international formats with country codes or local Chinese mobile numbers. ```APIDOC ## phone(number, [countryCode]) ### Description Validates if a given phone number string is valid. If a country code is provided, it validates against that specific region; otherwise, it defaults to Chinese mobile number validation. ### Parameters - **number** (string) - Required - The phone number to validate. - **countryCode** (string) - Optional - The 3-letter ISO country code (e.g., 'CHN', 'USA', 'HKG'). ### Returns - **boolean** - Returns true if the number is valid, false otherwise. ``` -------------------------------- ### ISmsManager.Send (Multi) Source: https://github.com/yunpian/sms/blob/master/thirdparty/csharp/README.md Sends different SMS content to multiple mobile numbers in a single batch. ```APIDOC ## Task Send(MultiSendSms sms) ### Description Sends different SMS content to multiple mobile numbers. The number of text entries must match the number of mobile numbers. ### Parameters - **sms** (MultiSendSms) - Required - Contains lists of mobile numbers and corresponding SMS text contents. ``` -------------------------------- ### Send Single Template SMS Source: https://github.com/yunpian/sms/blob/master/thirdparty/nodejs/yunpian-sms-client/README.md Send a single SMS using a predefined template. ```javascript provider.sendSingleTplSms({ mobile: mobile, tpl_id: 1411507, tpl_value: "#code#=1411507" }).then(function (result) { if (result) { console.log(result); } }).catch(function (err) { console.log(err); }); ``` -------------------------------- ### ISmsManager.Send (Batch) Source: https://github.com/yunpian/sms/blob/master/thirdparty/csharp/README.md Sends the same SMS content to multiple mobile numbers in a single batch. ```APIDOC ## Task Send(BatchSendSms sms) ### Description Sends the same SMS content to a list of mobile numbers. ### Parameters - **sms** (BatchSendSms) - Required - Contains a list of mobile numbers and the shared SMS text content. ``` -------------------------------- ### SMS API Interfaces and Models Source: https://github.com/yunpian/sms/blob/master/thirdparty/csharp/README.md Defines the ISmsManager interface and supporting models for single, batch, and multi-content SMS sending. ```csharp public interface ISmsManager { /// /// 单条发送 /// 一次发送一条短信,常用于短信验证、找回密码、短信登录、监控报警 /// /// /// Task Send(SingleSendSms sms); /// /// 批量发送相同内容 /// 批量发送订单状态通知,活动信息群发 /// /// /// Task Send(BatchSendSms sms); /// /// 批量发送不同内容 /// 批量发送短信内容带变量的订单状态通知,活动信息群发 /// /// /// Task Send(MultiSendSms sms); } public class SingleSendSms { /// /// 接收的手机号 /// public string Mobile { get; set; } /// /// 已审核短信模板 /// public string Text { get; set; } /// /// 其它附加参数 /// public SendSmsOption Option { get; set; } } public class BatchSendSms { /// /// 接收的手机号;发送多个手机号请以逗号分隔,一次不要超过1000个; /// public List Mobile { get; set; } /// /// 已审核短信模板 /// public string Text { get; set; } /// /// 其它附加参数 /// public SendSmsOption Option { get; set; } } public class MultiSendSms { /// /// 接收的手机号;发送多个手机号请以逗号分隔,一次不要超过1000个; /// public List Mobile { get; set; } /// /// 已审核短信模板,多个已审核短信模板请使用UTF-8做urlencode; /// 使用逗号分隔,一次不要超过1000条且已审核短信模板条数必须与手机号个数相等 /// public List Text { get; set; } /// /// 其它附加参数 /// public SendSmsOption Option { get; set; } } public class SmsResult : ApiResultBase { /// /// 成功发送总数 /// public int Total_Count { get; set; } /// /// 扣费金额,单位:元,类型:双精度浮点型/double /// public double Total_Fee { get; set; } /// /// 计费单位 /// public string Unit { get; set; } public IReadOnlyList Data { get; set; } } public class SendResultItem : ApiResultBase { /// /// 发送成功短信的计费条数(计费条数:70个字一条,超出70个字时按每67字一条计费) /// public int Count { get; set; } /// /// 扣费金额,单位:元,类型:双精度浮点型/double /// public double Fee { get; set; } /// /// 计费单位 /// public string Unit { get; set; } /// /// 发送手机号 /// public string Mobile { get; set; } /// /// 短信id,64位整型, 对应Java和C#的Long,不可用int解析 /// public long Sid { get; set; } } ``` -------------------------------- ### getSmsReplyRecord Source: https://github.com/yunpian/sms/blob/master/thirdparty/nodejs/yunpian-sms-client/README.md Retrieves records of SMS replies received. ```APIDOC ## provider.getSmsReplyRecord(params) ### Description Fetches the history of SMS replies within a specified time range. ### Parameters - **start_time** (string) - Required - Start time for the query. - **end_time** (string) - Required - End time for the query. - **page_num** (number) - Required - The page number to retrieve. - **page_size** (number) - Required - The number of records per page (max 100). - **mobile** (string) - Optional - Filter by a specific mobile number. ``` -------------------------------- ### ISmsManager.Send (Single) Source: https://github.com/yunpian/sms/blob/master/thirdparty/csharp/README.md Sends a single SMS message, typically used for verification codes or alerts. ```APIDOC ## Task Send(SingleSendSms sms) ### Description Sends a single SMS message to a specific mobile number. ### Parameters - **sms** (SingleSendSms) - Required - Contains the recipient mobile number and the SMS text content. ``` -------------------------------- ### getSmsStatusReport Source: https://github.com/yunpian/sms/blob/master/thirdparty/nodejs/yunpian-sms-client/README.md Retrieves the delivery status reports for sent SMS messages. ```APIDOC ## provider.getSmsStatusReport(params) ### Description Fetches the status reports for sent SMS messages. ### Parameters - **page_size** (number) - Optional - The number of records to return per page. ``` -------------------------------- ### Send Batch SMS Source: https://github.com/yunpian/sms/blob/master/thirdparty/nodejs/yunpian-sms-client/README.md Send SMS messages to multiple recipients. ```javascript provider.sendBatchSms({mobile:'your mobile,your girl mobile...',text:text}).then(function(result){ if(result){ console.log(result); } }).catch(function(err){ console.log(err); }); ``` -------------------------------- ### sendBatchSms Source: https://github.com/yunpian/sms/blob/master/thirdparty/nodejs/yunpian-sms-client/README.md Sends a batch of SMS messages to multiple mobile numbers. ```APIDOC ## provider.sendBatchSms(params) ### Description Sends SMS messages to multiple mobile numbers in a single request. ### Parameters - **mobile** (string) - Required - A comma-separated list of mobile numbers. - **text** (string) - Required - The content of the SMS. ``` -------------------------------- ### Validate Phone Numbers Source: https://github.com/yunpian/sms/blob/master/thirdparty/nodejs/yunpian-sdk/README.md Validate phone numbers with or without country codes and region-specific matching. ```js import {phone} from 'yunpian-sdk'; // 加区号匹配国际各国号码格式 phone('+8613312345678'); // true phone('+85265698900'); // true phone('+112345678'); // false // 不加区号按中国号码匹配 phone('13312341234'); // true phone('112345678'); // false // 按地区匹配 // 地区码使用3位缩写国家代码(大写) phone('+18175698900', 'USA'); // true phone('13212345678', 'CHN'); // true phone('+18175698900', 'CHN'); // false phone('13212345678', 'HKG'); // false ``` ```js var phone = require('yunpian-sdk').phone; phone('+8613312345678'); // true phone('13312341234'); // true phone('13212345678', 'CHN'); // true ``` -------------------------------- ### sendSingleSms Source: https://github.com/yunpian/sms/blob/master/thirdparty/nodejs/yunpian-sms-client/README.md Sends a single SMS message to a specified mobile number. ```APIDOC ## provider.sendSingleSms(params) ### Description Sends a single SMS message to a specific mobile number. ### Parameters - **mobile** (string) - Required - The recipient's mobile number. - **text** (string) - Required - The content of the SMS. - **uid** (string) - Optional - A unique identifier for the message. ### Response - **result** (object) - The API response containing the status of the message delivery. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.