首先感谢文扬_的思路分享。我是按照第一种方法做的。(想看效果下一个沪江网校APP在我的里面点击我的学生证即可查看)
我直接下载了微信SDK1.8.3范例代码一番配置后直接在代码中修改。
主要分为三个步骤

  1. 发起微信消息订阅
    SendMsgToWeChatViewController中定位到subscription方法
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    - (void)subscription
    {
    [UIAlertView requestWithTitle:@"请输入scene" message:@"scene" defaultText:@"1000" sure:^(UIAlertView *alertView, NSString *text) {
    UInt32 scene = (UInt32)[text integerValue];
    [UIAlertView requestWithTitle:@"输入templateId" message:@"templateId" defaultText:@"这里输入templateId" sure:^(UIAlertView *alertView, NSString *text) {
    NSString *templateId = text;

    [UIAlertView requestWithTitle:@"请输入reserved" message:nil defaultText:@"" sure:^(UIAlertView *alertView, NSString *text) {
    NSString *reserved = text;

    WXSubscribeMsgReq *req = [[WXSubscribeMsgReq alloc] init];
    req.scene = scene;
    req.templateId = templateId;
    req.reserved = reserved;

    [WXApi sendReq:req];
    }];
    }];
    }];
    }
    记得把defaultText改成你的APP一次性订阅消息的模板id

具体各个属性有啥意思去文档中找吧
调用这个方法跳转微信,用户点击授权跳转回来会在- (void)managerDidRecvSubscribeMsgResponse:(WXSubscribeMsgResp *)response获得templateId openId scene三个参数

  1. 获取授权Token
    GET调用接口获取AccessToken

https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET

1
2
3
4
5
6
[Request getRequestByServiceUrl:@"https://api.weixin.qq.com/cgi-bin/token?"
andApi:@"grant_type=client_credential&appid=appid&secret=scret"
andParams:nil
andCallBack:^(id _Nonnull obj) {
token = obj[@"access_token"];//accessToken
}];
  1. 发送订阅消息
    基于前两步获得的accessToken templateId openId scene
    POST调用接口https://api.weixin.qq.com/cgi-bin/message/template/subscribe?access_token=ACCESS_TOKEN
1
2
3
4
5
6
7
8
9
10
11
12
[Request postRequestByServiceUrl:@"https://api.weixin.qq.com/cgi-bin/message/template/subscribe?"
andApi:[NSString stringWithFormat:@"access_token=%@",obj[@"access_token"]]
andParams:@{@"touser":response.openId,@"template_id":response.templateId,@"url":@"http://www.baidu.com",@"scene":[NSNumber numberWithInt:response.scene],@"title":@"消息",@"data":@{@"content":@{@"color":@"#173177",@"value":@"点击关注公众号"}}}
andCallBack:^(id _Nonnull obj2) {
if ([obj2[@"errcode"] integerValue] == 0) {
dispatch_async(dispatch_get_main_queue(), ^{
[UIAlertView showWithTitle:@"成功" message:nil sure:^(UIAlertView *alertView, NSString *text) {
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"weixin://"]];
}];
});
}
}];

参数简单说明

{
“touser”:”OPENID”,//openid
“template_id”:”TEMPLATE_ID”,//
“url”:”URL”,//跳转url
“scene”:”SCENE”,
“title”:”TITLE”,//消息名字
“data”:{
“content”:{
“value”:”VALUE”,//消息主体
“color”:”COLOR”//字体颜色 例:#173177
}
}
}
###注意点

  1. bundleid 和平台注册的要一致
  2. 把URL type改成wx…… 微信平台的appid
    最终效果:
    IMG_4073.PNG