物联网卡平台各种语言api

c语言_登录 ```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/cus...

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

c语言_登录

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

go_登录

  1. package main
  2. import (
  3. "fmt"
  4. "strings"
  5. "net/http"
  6. "io/ioutil"
  7. )
  8. func main() {
  9. url := "http://sim.openluat.com/api/auth/customer/login"
  10. payload := strings.NewReader("{\"phone\":\"用户名\",\"password\":\"密码\"}")
  11. req, _ := http.NewRequest("POST", url, payload)
  12. req.Header.Add("Content-Type", "application/json")
  13. req.Header.Add("cache-control", "no-cache")
  14. res, _ := http.DefaultClient.Do(req)
  15. defer res.Body.Close()
  16. body, _ := ioutil.ReadAll(res.Body)
  17. fmt.Println(res)
  18. fmt.Println(string(body))
  19. }

java OK HTTP_登录

  1. OkHttpClient client = new OkHttpClient();
  2. MediaType mediaType = MediaType.parse("application/json");
  3. RequestBody body = RequestBody.create(mediaType, "{\"phone\":\"用户名\",\"password\":\"密码\"}");
  4. Request request = new Request.Builder()
  5. .url("http://sim.openluat.com/api/auth/customer/login")
  6. .post(body)
  7. .addHeader("Content-Type", "application/json")
  8. .addHeader("cache-control", "no-cache")
  9. .build();
  10. Response response = client.newCall(request).execute();

nodejs_登录

  1. var unirest = require("unirest");
  2. var req = unirest("POST", "http://sim.openluat.com/api/auth/customer/login");
  3. req.headers({
  4. "cache-control": "no-cache",
  5. "Content-Type": "application/json"
  6. });
  7. req.type("json");
  8. req.send({
  9. "phone": "用户名",
  10. "password": "密码"
  11. });
  12. req.end(function (res) {
  13. if (res.error) throw new Error(res.error);
  14. console.log(res.body);
  15. });

objective-c_登录

  1. #import <Foundation/Foundation.h>
  2. NSDictionary *headers = @{ @"Content-Type": @"application/json",
  3. @"cache-control": @"no-cache" };
  4. NSDictionary *parameters = @{ @"phone": @"用户名",
  5. @"password": @"密码" };
  6. NSData *postData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil];
  7. NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://sim.openluat.com/api/auth/customer/login"]
  8. cachePolicy:NSURLRequestUseProtocolCachePolicy
  9. timeoutInterval:10.0];
  10. [request setHTTPMethod:@"POST"];
  11. [request setAllHTTPHeaderFields:headers];
  12. [request setHTTPBody:postData];
  13. NSURLSession *session = [NSURLSession sharedSession];
  14. NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
  15. completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
  16. if (error) {
  17. NSLog(@"%@", error);
  18. } else {
  19. NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
  20. NSLog(@"%@", httpResponse);
  21. }
  22. }];
  23. [dataTask resume];

Ocaml_登录

  1. open Cohttp_lwt_unix
  2. open Cohttp
  3. open Lwt
  4. let uri = Uri.of_string "http://sim.openluat.com/api/auth/customer/login" in
  5. let headers = Header.init ()
  6. |> fun h -> Header.add h "Content-Type" "application/json"
  7. |> fun h -> Header.add h "cache-control" "no-cache"
  8. in
  9. let body = Cohttp_lwt_body.of_string "{\"phone\":\"用户名\",\"password\":\"密码\"}" in
  10. Client.call ~headers ~body `POST uri
  11. >>= fun (res, body_stream) ->
  12. (* Do stuff with the result *)

php_登录

  1. <?php
  2. $request = new HttpRequest();
  3. $request->setUrl('http://sim.openluat.com/api/auth/customer/login');
  4. $request->setMethod(HTTP_METH_POST);
  5. $request->setHeaders(array(
  6. 'cache-control' => 'no-cache',
  7. 'Content-Type' => 'application/json'
  8. ));
  9. $request->setBody('{"phone":"用户名","password":"密码"}');
  10. try {
  11. $response = $request->send();
  12. echo $response->getBody();
  13. } catch (HttpException $ex) {
  14. echo $ex;
  15. }

ruby_登录

  1. require 'uri'
  2. require 'net/http'
  3. url = URI("http://sim.openluat.com/api/auth/customer/login")
  4. http = Net::HTTP.new(url.host, url.port)
  5. request = Net::HTTP::Post.new(url)
  6. request["Content-Type"] = 'application/json'
  7. request["cache-control"] = 'no-cache'
  8. request.body = "{\"phone\":\"用户名\",\"password\":\"密码\"}"
  9. response = http.request(request)
  10. puts response.read_body

swift_登录

  1. import Foundation
  2. let headers = [
  3. "Content-Type": "application/json",
  4. "cache-control": "no-cache"
  5. ]
  6. let parameters = [
  7. "phone": "用户名",
  8. "password": "密码"
  9. ] as [String : Any]
  10. let postData = JSONSerialization.data(withJSONObject: parameters, options: [])
  11. let request = NSMutableURLRequest(url: NSURL(string: "http://sim.openluat.com/api/auth/customer/login")! as URL,
  12. cachePolicy: .useProtocolCachePolicy,
  13. timeoutInterval: 10.0)
  14. request.httpMethod = "POST"
  15. request.allHTTPHeaderFields = headers
  16. request.httpBody = postData as Data
  17. let session = URLSession.shared
  18. let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  19. if (error != nil) {
  20. print(error)
  21. } else {
  22. let httpResponse = response as? HTTPURLResponse
  23. print(httpResponse)
  24. }
  25. })
  26. dataTask.resume()

返回数据

  1. {
  2. "code": 0,
  3. "data": {
  4. "api_url": "/api/wechat/openapidoc",
  5. "email": "xxxxx@airm2m.com",
  6. "enable_recharge": 0,
  7. "name": "公司",
  8. "phone": "130xxxxxx",
  9. "role": 0
  10. },
  11. "msg": ""
  12. }
  • 发表于 2019-04-12 12:17
  • 阅读 ( 2455 )

你可能感兴趣的文章

相关问题

2 条评论

请先 登录 后评论
不写代码的码农
大仙

程序员

9 篇文章

作家榜 »

  1. 技术销售Delectate 43 文章
  2. 陈夏 26 文章
  3. 国梁 24 文章
  4. miuser 21 文章
  5. 晨旭 20 文章
  6. 朱天华 19 文章
  7. 金艺 19 文章
  8. 杨奉武 18 文章