iOS App获取微信发票列表

需求就是外部app 获取微信里的发票助手里面的发票信息。

先看看微信文档
https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Reimburser_API_List.html#4

(1)先获取Token

就是用Get 请求获取token ,参数有两个APPID,和APPSECRET ,这两个参数我们在平台创建APP时候就得到了

 NSString *url = [NSString stringWithFormat:@"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%@&secret=%@",@"你的appid",@"你的secret"];

参考文档:https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/Nontax_Bill/API_list.html#1.1

(2)获取ticket

就是用Get 请求获取ticket ,参数是上一步获取的token。其他参数定值。

 NSString *url = [NSString stringWithFormat:@"https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%@&type=wx_card",token];

参考文档:https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/Nontax_Bill/API_list.html#1.1

(3)获取签名数据

看一下文档里的签名算法
参考文档:https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html#62

主要代码:

#import 

- (NSString *)sha1:(NSString *)input

{

NSData *data = [input dataUsingEncoding:NSUTF8StringEncoding];

uint8_t digest[CC_SHA1_DIGEST_LENGTH];

CC_SHA1(data.bytes, (unsigned int)data.length, digest);

NSMutableString *output = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH * 2];

for(int i=0; i

(4)吊起微信获取发票信息

-(void)goTowechat:(NSString *)sign
{
    
    NSDictionary *parDic = [[NSUserDefaults standardUserDefaults] objectForKey:@"cardSignDic"];

    WXChooseInvoiceReq *chooseInvoiceReq = [[WXChooseInvoiceReq alloc] init];

    chooseInvoiceReq.appID = @"你的appID";

    //前面获取的

    chooseInvoiceReq.cardSign = sign;

    //前面存的

    chooseInvoiceReq.nonceStr = [parDic objectForKey:@"nonceStr"];

    chooseInvoiceReq.signType = @"SHA1";

    //前面存的

    chooseInvoiceReq.timeStamp = [[parDic objectForKey:@"timestamp"] doubleValue];

    [WXApi sendReq:chooseInvoiceReq completion:^(BOOL success) {
        
        
        
    }];
}

回调方法在微信的回调代理方法中

主要代码

- (void)onResp:(BaseResp *)resp
{
   
  
   if ([resp isKindOfClass:[WXChooseInvoiceResp class]]){

   //这里面有数组,自己怎么用都行了,over

   WXChooseInvoiceResp *chooseInvoiceResp = (WXChooseInvoiceResp *)resp;

       NSLog(@"%@",chooseInvoiceResp.cardAry);
       
       
   }

   
}




你可能感兴趣的:(iOS App获取微信发票列表)