转自:http://www.cnblogs.com/littleBit/p/5977572.html
1.app跳转微信
1、app跳转微信公众号在工程中添加pch文件,导入 WXApi.h头文件,并在你需要跳转的界面增加WXApiDelegate协议在你的跳转方法中添加一下代码:
JumpToBizProfileReq *req = [JumpToBizProfileReq new];
req.username = @"gh_64a69d298ecf"; // 原始ID
req.profileType = WXBizProfileType_Normal;
req.extMsg = @"";[WXApi sendReq:req];
这样APP就可以掉起微信界面,进入微信公众号(如果之前没有关注过此微信公众号,就会进入微信公众号的关注界面)
2、APP跳转到微信相关的其他网页(如微信小店相关商品信息界面)
OpenWebviewReq *req = [OpenWebviewReq new];
req.url = @"需要微信内置浏览器打开的网址";
[WXApi sendReq:req];
PS:原始ID: 申请公共号时系统给你的唯一编号,有此 id你更改微信号后依然能绑定公共号APPID: 开通 api 服务时,系统给你的唯一编号APPSECRET: 通俗一点儿来说就是密钥
生成订单相关代码
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSDictionary *signParaDic = @{@"schoolId":schoolId,
@"studentId":studentId,
@"parentId":parentId,
@"parentTel":phone,
@"totalFee":[NSString stringWithFormat:@"%i",payProduct.totalFee],
@"productId":[NSString stringWithFormat:@"%i",payProduct.productId],
@"productName":payProduct.productName};
NSString *sign = [EncodeParameter md5:signParaDic];
NSDictionary *parameters = @{@"schoolId":schoolId,
@"parentId":parentId,
@"studentId":studentId,
@"parentTel":phone,
@"totalFee":[NSString stringWithFormat:@"%i",payProduct.totalFee],
@"productId":[NSString stringWithFormat:@"%i",payProduct.productId],
@"productName":payProduct.productName,
@"sign":sign};
NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] requestWithMethod:@"POST" URLString:WechatPlaceOrderAPI parameters:parameters error:nil];
_palceOrderOperation = [manager HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
//NSDictionary *resDic = (NSDictionary *)responseObject;
NSNumber *code = [resDic objectForKey:@"result"];
NSString *msg = [resDic objectForKey:@"message"];
if ([code integerValue] == Success) {
WeChatPreOrder *preOrder = [[WeChatPreOrder alloc] initWithDic:resDic];
if (self.delegate && [self.delegate respondsToSelector:@selector(placeOrderSucess:preOder:)]) {
[self.delegate placeOrderSucess:self preOder:preOrder];
}} else if ([code integerValue] == 300) {
if (self.delegate && [self.delegate respondsToSelector:@selector(placeOrderFailed:error:)]) {
[self.delegate placeOrderFailed:self error:msg];
}}else { if (self.delegate && [self.delegate respondsToSelector:@selector(placeOrderFailed:error:)]) {
[self.delegate placeOrderFailed:self error:RequestError];
} }} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
if (self.delegate && [self.delegate respondsToSelector:@selector(placeOrderFailed:error:)]) {
[self.delegate placeOrderFailed:self error:RequestError];
}}];