• 欢迎大家分享资料!前往留言板评论即可!

物联网卡平台各种语言api

合宙 模组资料网 2年前 (2021-05-15) 391次浏览 0个评论 扫描二维码

最近在对接合宙物联网卡系统和我自建的系统
网上的例子只有python的不太方便
提供别的例子方便下大家

c语言_登录

CURL *hnd = curl_easy_init();
curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(hnd, CURLOPT_URL, "http://sim.openluat.com/api/auth/customer/login");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "cache-control: no-cache");
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "{\"phone\":\"用户名\",\"password\":\"密码\"}");
CURLcode ret = curl_easy_perform(hnd);

go_登录

package main

import (
    "fmt"
    "strings"
    "net/http"
    "io/ioutil"
)

func main() {
    url := "http://sim.openluat.com/api/auth/customer/login"
    payload := strings.NewReader("{\"phone\":\"用户名\",\"password\":\"密码\"}")
    req, _ := http.NewRequest("POST", url, payload)
    req.Header.Add("Content-Type", "application/json")
    req.Header.Add("cache-control", "no-cache")
    res, _ := http.DefaultClient.Do(req)
    defer res.Body.Close()
    body, _ := ioutil.ReadAll(res.Body)
    fmt.Println(res)
    fmt.Println(string(body))
}

java OK HTTP_登录

OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"phone\":\"用户名\",\"password\":\"密码\"}");
Request request = new Request.Builder()
  .url("http://sim.openluat.com/api/auth/customer/login")
  .post(body)
  .addHeader("Content-Type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();

nodejs_登录

var unirest = require("unirest");

var req = unirest("POST", "http://sim.openluat.com/api/auth/customer/login");

req.headers({
  "cache-control": "no-cache",
  "Content-Type": "application/json"
});

req.type("json");
req.send({
  "phone": "用户名",
  "password": "密码"
});

req.end(function (res) {
  if (res.error) throw new Error(res.error);

  console.log(res.body);
});

objective-c_登录

#import <Foundation/Foundation.h>

NSDictionary *headers = @{ @"Content-Type": @"application/json",
                           @"cache-control": @"no-cache" };
NSDictionary *parameters = @{ @"phone": @"用户名",
                              @"password": @"密码" };

NSData *postData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://sim.openluat.com/api/auth/customer/login"]
                                                       cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                   timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:postData];

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
                                            completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                if (error) {
                                                    NSLog(@"%@", error);
                                                } else {
                                                    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
                                                    NSLog(@"%@", httpResponse);
                                                }
                                            }];
[dataTask resume];

Ocaml_登录

open Cohttp_lwt_unix
open Cohttp
open Lwt

let uri = Uri.of_string "http://sim.openluat.com/api/auth/customer/login" in
let headers = Header.init ()
  |> fun h -> Header.add h "Content-Type" "application/json"
  |> fun h -> Header.add h "cache-control" "no-cache"
in
let body = Cohttp_lwt_body.of_string "{\"phone\":\"用户名\",\"password\":\"密码\"}" in

Client.call ~headers ~body `POST uri
>>= fun (res, body_stream) ->
  (* Do stuff with the result *)

php_登录

<?php

request = new HttpRequest();request->setUrl('http://sim.openluat.com/api/auth/customer/login');
request->setMethod(HTTP_METH_POST);request->setHeaders(array(
  'cache-control' => 'no-cache',
  'Content-Type' => 'application/json'
));

request->setBody('{"phone":"用户名","password":"密码"}');

try {response = request->send();

  echoresponse->getBody();
} catch (HttpException ex) {
  echoex;
}

ruby_登录

require 'uri'
require 'net/http'

url = URI("http://sim.openluat.com/api/auth/customer/login")

http = Net::HTTP.new(url.host, url.port)

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request["cache-control"] = 'no-cache'
request.body = "{\"phone\":\"用户名\",\"password\":\"密码\"}"

response = http.request(request)
puts response.read_body

swift_登录

import Foundation

let headers = [
  "Content-Type": "application/json",
  "cache-control": "no-cache"
]
let parameters = [
  "phone": "用户名",
  "password": "密码"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "http://sim.openluat.com/api/auth/customer/login")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()

返回数据

{
    "code": 0,
    "data": {
        "api_url": "/api/wechat/openapidoc",
        "email": "[email protected]",
        "enable_recharge": 0,
        "name": "公司",
        "phone": "130xxxxxx",
        "role": 0
    },
    "msg": ""
}

转载请注明原文链接:物联网卡平台各种语言api
喜欢 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址