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 #define kJHAPIS_LIFE_WEATHER_IP @"juhe.apis.weather.ip" //3、根据IP查询天气 @brief 全国天气 -> 根据GPS坐标查询天气 @param lon string 必填 经度,如:116.39277 @param lat string 必填 纬度,如:39.933748 #define kJHAPIS_LIFE_WEATHER_GEO @"juhe.apis.weather.geo" //4、根据GPS坐标查询天气 @brief 全国天气 -> 城市天气三小时预报 @param cityname string 必填 城市名,如:"苏州" #define kJHAPIS_LIFE_WEATHER_FORECAST3H @"juhe.apis.weather.forecast3h" //5、城市天气三小时预报 @brief 全国天气 -> 支持城市列表 #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":@"苏州",255);">/* 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 :juhe.apis.weather.index (宏 : kJHAPIS_LIFE_WEATHER_INDEX )
返回字段 :
2. 天气种类及标识列表
API :juhe.apis.weather.uni (宏 :kJHAPIS_LIFE_WEATHER_UNI )
返回字段 :
3. 根据IP查询天气
API :juhe.apis.weather.ip (宏 :kJHAPIS_LIFE_WEATHER_IP )
返回字段同juhe.apis.weather.index(根据城市名/id查询天气)。
4. 根据GPS坐标查询天气
API :juhe.apis.weather.geo (宏 :kJHAPIS_LIFE_WEATHER_GEO)
返回字段同juhe.apis.weather.index(根据城市名/id查询天气)。
5. 城市天气三小时预报
API :juhe.apis.weather.forecast3h (宏 :kJHAPIS_LIFE_WEATHER_FORECAST3H )
返回字段 :
6. 支持城市列表
API :juhe.apis.weather.citys (宏 :kJHAPIS_LIFE_WEATHER_CITYS )
返回字段 :
7 . 全国天气预报错误码
5,更多聚合数据SDK接口,访问这里: http://www.juhe.cn/juhesdk/idocs (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|