Skip to content

Latest commit

 

History

History
164 lines (131 loc) · 5.59 KB

GetCredit.md

File metadata and controls

164 lines (131 loc) · 5.59 KB

راهنمای متد GetCredit

با استفاده از این متد شما می توانید از باقیمانده اعتبار پیام کوتاه خود مطلع شوید . جهت به کارگیری آن آدرس URL زیر را فراخوانی نمایید:

https://sms.sunwaysms.com/smsws/HttpService.ashx?service=GetCredit&username=$UserName$&password=$Password$

با توجه به جدول ذیل کلمات کلیدی این متد را مقدار دهی نمایید.

پارامترهای ورودی

نامنوعاجباری / اختیاریتوضیح
UserNameStringاجبارینام کاربری
PasswordStringاجباریکلمه عبور

خروجی متد

کلیدتوضیح
Stringباقیمانده اعتبار پیام کوتاه کاربر یا کد خطا

نکات مهم در مورد کار با متد GetCredit

  • شما می توانید قبل از هر ارسال با استفاده از این متد از باقیمانده اعتبار پیام کوتاه خود مطلع شوید و در صورت کمبود اعتبار ، از ارسال پیامک ها و بروز خطا جلوگیری نمایید .

نمونه کد

PHP

class SMS
{
    function get_data($Data) {
        $url = "https://sms.sunwaysms.com/smsws/HttpService?";
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url . $Data);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
         $data = curl_exec($ch);
         curl_close($ch);
        return $data;
    }

    function GetCredit($UserName, $Password) {
        return $this->get_data("service=GetCredit&UserName=" . urlencode($UserName) . "&Password=" . urlencode($Password));
    }
}

Java

import java.net.*;
import java.nio.charset.Charset;
import java.io.*;

import com.google.gson.*;

public class UrlAPI {

    static String link = "https://sms.sunwaysms.com/smsws/HttpService?";
    static Gson gson = new Gson();

    public static void main(String[] args) {
        
    }

    public static String getUrl(String Url) throws Exception {
        String temp = "";
        try {
            URL url = new URL(link + Url);
            // Get the response
            URLConnection urlConnection = url.openConnection();
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    urlConnection.getInputStream(), Charset.forName("UTF-8")));

            String line = "";
            while ((line = reader.readLine()) != null) {
                temp += line;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return temp;
    }

    public static String GetCredit(String UserName, String Password)
            throws Exception {
        return getUrl("service=GetCredit&UserName=" + encode(UserName)
                + "&Password=" + encode(Password));
    }
}

C#

public static class API {
    const string URL = "https://sms.sunwaysms.com/smsws/HttpService?";

    /// <summary>
    /// Get Account Credit
    /// </summary>
    /// <param name="UserName">String</param>
    /// <param name="Password">String</param>
    /// <returns>long Credit</returns>
    public static long GetCredit(string UserName, string Password) {
        WebRequest request = WebRequest.Create(URL + "service=GetCredit&UserName=" + UserName + "&Password=" + Password);
        request.Method = "GET";
        WebResponse response = request.GetResponse();
        using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) {
            var result = reader.ReadToEnd();
            return String.IsNullOrEmpty(result) ? -1 : long.Parse(result);
        }
    }
}

VB.net

Imports System.Net
Imports System.IO
Imports System.Text
Imports System.Web.Script.Serialization

Public Class API
    Const URL As String = "https://sms.sunwaysms.com/smsws/HttpService?"

    ''' <summary>
    ''' Get Account Credit
    ''' </summary>
    ''' <param name="UserName">String</param>
    ''' <param name="Password">String</param>
    ''' <returns>long Credit</returns>
    Public Shared Function GetCredit(UserName As String, Password As String) As Long
        Dim request As WebRequest = WebRequest.Create(URL & "service=GetCredit&UserName=" & UserName & "&Password=" & Password)
        request.Method = "GET"
        Dim response As WebResponse = request.GetResponse()
        Using reader As New StreamReader(response.GetResponseStream(), Encoding.UTF8)
            Dim result = reader.ReadToEnd()
            Return If([String].IsNullOrEmpty(result), -1, Long.Parse(result))
        End Using
    End Function

End Class