聚合数据iOS SDK 全国天气预报演示示例

1,将聚合数据SDK(JuheApis.framework)添加到你的程序中来,SDK依赖的包包括:



2,在聚合SDK Framework的JHSDKAPIPath.h文件中找到快递查询接口宏,以及字典参数

/*** 全国天气预报 ***/

/**
  @brief 全国天气 -> 根据城市名/id查询天气
  @param cityname     string     必填     城市名或城市ID,如:"苏州"
  @param dtype       string     必填     返回数据格式:json或xml,默认json
  @param format      int     非必填     未来6天预报(future)两种返回格式,1或2,默认1
 */
#define kJHAPIS_LIFE_WEATHER_INDEX          @"juhe.apis.weather.index"          //1、根据城市名/id查询天气

/**
 @brief 全国天气 -> 天气种类及标识列表
 @param dtype       string     非必填     返回数据的格式,xml或json,默认json
 */
#define kJHAPIS_LIFE_WEATHER_UNI            @"juhe.apis.weather.uni"            //2、天气种类及标识列表
/**
 @brief 全国天气 -> 根据IP查询天气
 @param ip          string     必填     ip地址,如:58.215.185.154
 @param dtype       string     必填     返回数据格式:json或xml,默认json
 @param format      int     非必填     未来6天预报(future)两种返回格式,1或2,默认1
 */
#define kJHAPIS_LIFE_WEATHER_IP             @"juhe.apis.weather.ip"             //3、根据IP查询天气
/**
 @brief 全国天气 -> 根据GPS坐标查询天气
 @param lon         string     必填     经度,如:116.39277
 @param lat         string     必填     纬度,如:39.933748
 @param format      int     非必填     未来6天预报(future)两种返回格式,1或2,默认1
 @param dtype       string     必填     返回数据格式:json或xml,默认json
 */
#define kJHAPIS_LIFE_WEATHER_GEO            @"juhe.apis.weather.geo"            //4、根据GPS坐标查询天气
/**
 @brief 全国天气 -> 城市天气三小时预报
 @param cityname    string     必填     城市名,如:"苏州"
 @param dtype       string     必填     返回数据格式:json或xml,默认json
 */
#define kJHAPIS_LIFE_WEATHER_FORECAST3H     @"juhe.apis.weather.forecast3h"     //5、城市天气三小时预报
/**
 @brief 全国天气 -> 支持城市列表
 @param dtype       string     非必填     返回数据的格式,xml或json,默认json
 */

#define kJHAPIS_LIFE_WEATHER_CITYS          @"juhe.apis.weather.citys"          //6、支持城市列表


3,全国天气预报接口在程序中调用方法(将ViewController.m改为.mm)

#import "ViewController.h"

#import <JuheApis/JuheAPI.h>
#import <JuheApis/JHOpenidSupplier.h>
#import <JuheApis/JHSDKAPIPath.h>

@interface ViewController ()
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [[JHOpenidSupplier shareSupplier] registerJuheAPIByOpenId:@"申请到的OpenId“];
    
    UIButton* beginBtn=[UIButton buttonWithType:UIButtonTypeSystem];
    beginBtn.frame=CGRectMake(20, 111, 280, 40);
    [beginBtn setTitle:@"开始" forState:UIControlStateNormal];
    [beginBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    [beginBtn addTarget:self action:@selector(doTestAction) forControlEvents:UIControlEventTouchUpInside];
    [beginBtn setBackgroundImage:[UIImage imageNamed:@"button5"] forState:UIControlStateNormal];
    [self.view addSubview:beginBtn];
}

- (void)doTestAction
{
   /* 1. 根据城市名/id查询天气 */
   [self test : kJHAPIS_LIFE_WEATHER_INDEX         parameters:@{@"cityname":@"苏州" , @"dtype":@"json" } ];


   /* 2.  天气种类及标识列表 */

   [self test : kJHAPIS_LIFE_WEATHER_UNI        parameters:@{@"dtype":@"json"} ];


   /* 3.  根据IP查询天气 */

   [self test : kJHAPIS_LIFE_WEATHER_IP         parameters:@{@"ip":@"58.215.185.154" , @"dtype":@"json"} ];


   /* 4.  根据GPS坐标查询天气 */

   [self test : kJHAPIS_LIFE_WEATHER_GEO        parameters:@{@"lon":@"116.39277" , @"lat":@"39.933748" , @"dtype":@"json"  } ];


  /* 5.  城市天气三小时预报  */

   [self test : kJHAPIS_LIFE_WEATHER_FORECAST3H        parameters:@{@"cityname":@"苏州" , @"dtype":@"json" } ];


  /* 6.  支持城市列表  */

   [self test : kJHAPIS_LIFE_WEATHER_CITYS         parameters:@{@"dtype":@"json" } ];


}

- (void)test:(NSString *)path  parameters:(NSDictionary *)parameters{
    
    JuheAPI *juheapi = [JuheAPI shareJuheApi];
    [juheapi executeWorkWithAPI:path
                     parameters:parameters
                        success:^(id responseObject){
                            if ([[parameters objectForKey:@"dtype"] isEqualToString:@"xml"]) {
                                NSLog(@"***xml*** \n %@", responseObject);
                            }else{
                                int error_code = [[responseObject objectForKey:@"error_code"] intValue];
                                if (!error_code) {
                                    NSLog(@" %@", responseObject);
                                }else{
                                    NSLog(@" %@", responseObject);
                                }
                            }
                            
                        } failure:^(NSError *error) {
                            NSLog(@"error:   %@",error.description);
                        }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end


4,全国天气预报接口返回数据说明以及错误码说明

 1. 根据城市名/id查询天气 

  API : kJHAPIS_LIFE_WEATHER_INDEX  

  返回字段 :

名称

 

 

类型

说明

resultcode

 

 

int

返回码

reason

 

 

string

返回说明

result

 

 

dictionary

返回结果

sk

 

 

dictionary

当前实况天气

 

temp

 

int

当前温度

 

wind_direction

 

string

当前风向

 

wind_strength

 

string

当前风力

 

humidity

 

string

当前湿度

 

time

 

date

更新时间

today

 

 

dictionary

今日天气

 

city

 

string

城市

 

date_y

 

string

日期

 

week

 

string

星期

 

temperature

 

string

今日温度

 

weather

 

string

今日天气

 

weather_id

 

dictionary

天气唯一标识

 

 

  fa

Int

天气标识00:晴

 

 

  fb

int

天气标识53:霾 如果fa不等于fb,说明是组合天气

 

wind

 

string

风向与风力

 

dressing_index

 

string

穿衣指数(较冷)

 

dressing_advice

 

string

穿衣建议

 

uv_index

 

string

紫外线强度

 

comfort_index

 

string

舒适度指数

 

wash_index

 

string

洗车指数

 

travel_index

 

string

旅游指数

 

exercise_index

 

string

晨练指数

 

drying_index

 

string

干燥指数
future

 

 

array

未来几天天气(内部字典参数均能在today中找到)
error_code
 

 

 

int

错误码

   2.  天气种类及标识列表 

  API : kJHAPIS_LIFE_WEATHER_UNI

  返回字段 :

名称

 

类型

说明

resultcode

 

int

返回码

reason

 

string

返回说明

result

 

array

返回结果集

 

wid

string

天气唯一标示符

 

weather

string

天气

error_code

 

int

错误码


   3.  根据IP查询天气

  API : kJHAPIS_LIFE_WEATHER_IP

  返回字段同juhe.apis.weather.index(根据城市名/id查询天气)。


   4.  根据GPS坐标查询天气 

  API : kJHAPIS_LIFE_WEATHER_GEO

  返回字段同juhe.apis.weather.index(根据城市名/id查询天气)。


   5.  城市天气三小时预报 

  API : kJHAPIS_LIFE_WEATHER_FORECAST3H

  返回字段 :

名称

 

类型

说明

resultcode

 

int

返回码

reason

 

string

返回说明

result

 

array

返回结果集

 

weatherid

int

天气标识ID

 

weather

string

天气

 

temp1

string

低温

 

temp2

string

高温

 

sh

string

开始小时

 

eh

string

结束小时

 

wid

string

天气唯一标示符

 

date

string

日期

 

sfdate

string

完整开始时间

 

efdate

string

完整结束时间

error_code

 

int

错误码


  6.  支持城市列表 

  API :  kJHAPIS_LIFE_WEATHER_CITYS

  返回字段 :

名称

 

类型

说明

resultcode

 

int

返回码

reason

 

string

返回说明

result

 

dictionary

返回结果集

 

id

int

城市ID

 

province

string

省份名称

 

city

string

城市名称

 

district

string

城市/区名称

error_code

 

int

错误码


  7 . 全国天气预报错误码

 

错误码

 

203901

查询城市不能

 

203902

查询不到城市的天气

 

203903

查询出

 

203904

错误GPS

 

203905

GPS解析出提供的坐正确支持国

 

203906

IP地址错误

 

203907

查询不到IP地址相的天气信息


 

5, 更多聚合数据SDK接口,访问这里: http://www.juhe.cn/juhesdk/idocs

 

转载于:https://my.oschina.net/u/2009908/blog/325570

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值