IOS 통합 위 챗 결제 기능 의 실현 방법

IOS 통합 위 챗 결제 기능 의 실현 방법
STEP 1:위 챗 통합 SDK
https://pay.weixin.qq.com/wiki/doc/api/index.html     
클릭 하여 입장
해당 SDK 나 예제 를 다운로드 하면 예제 프로그램 을 볼 수 있 습 니 다.
두 번 째 단계:Xcode 에 위 챗 오픈 플랫폼 에서 신청 한 Appid 를 작성 합 니 다.
Xcode>info>URL Types  새로 추 가 된 Appid
세 번 째 단계:Appdelegate.m 에 위 챗 결제 와 리 셋 을 등록 합 니 다.

#import "WXApi.h"
     
WXApiDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  // Override point for customization after application launch.
  //self.window.backgroundColor = [UIColor clearColor];

  //       
  [WXApiregisterApp:PAY_WEIXIN_ID];

  
  returnYES;
}

// ios 9.0        
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options
{
  //   
  if ([url.schemeisEqualToString:PAY_WEIXIN_ID]) {
    [WXApihandleOpenURL:url delegate:(id<WXApiDelegate>)self];
  }
  
  //    
  if ([url.schemeisEqualToString:@"SearchPigeonWorld"]) {
    //           ,      
    [[AlipaySDKdefaultService] processOrderWithPaymentResult:urlstandbyCallback:^(NSDictionary *resultDic) {
      if ([self.appMyDelegaterespondsToSelector:@selector(payCenterWeixinOnResultWith:)]) {
        [self.appMyDelegatepayCenterWeixinOnResultWith:[resultDic[@"resultStatus"]intValue] ==9000 ? YES :NO];
      }
    }];
  }

  returnYES;
}


//       ,         ios 9.0        
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
  //   
  if ([url.schemeisEqualToString:PAY_WEIXIN_ID])
  {
    [WXApihandleOpenURL:url delegate:(id<WXApiDelegate>)self];
  }
  
  //    
  if ([url.hostisEqualToString:PAY_ALIPAY_appID]) {
    //           ,      
    [[AlipaySDKdefaultService] processOrderWithPaymentResult:urlstandbyCallback:^(NSDictionary *resultDic) {
      if ([self.appMyDelegaterespondsToSelector:@selector(payCenterWeixinOnResultWith:)]) {
        [self.appMyDelegatepayCenterWeixinOnResultWith:[resultDic[@"resultStatus"]intValue] ==9000 ? YES :NO];
      }
    }];
  }
  
  
  returnYES;
}


/**
            

 @param resp       
 */
- (void)onResp:(BaseResp*)resp
{
  if([respisKindOfClass:[PayRespclass]]){
    BOOL isPaySuccess =NO;
    switch (resp.errCode) {
      caseWXSuccess:
        isPaySuccess = YES;
        break;
      caseWXErrCodeUserCancel:
        isPaySuccess = NO;
        break;
      caseWXErrCodeSentFail:
        isPaySuccess = NO;
        break;
      caseWXErrCodeAuthDeny:
        isPaySuccess = NO;
        break;
      default:
        isPaySuccess = NO;
        break;
    }
    if ([self.appMyDelegaterespondsToSelector:@selector(payCenterWeixinOnResultWith:)]) {
      [self.appMyDelegatepayCenterWeixinOnResultWith:isPaySuccess];
    }
  }
}

STEP 4:위 챗 을 사용 하 는 곳 에서 결제 방법 을 호출 합 니 다.

#pragma mark 2.2.14(10)        ,        
- (void)getWebResponsePayWeixinInfo {
  NSDictionary *parameters =@{@"key" :appDelegate.userKeyString,
                 @"foundRecordId" : [self.payInfoDictobjectForKey:@"foundRecordId"]};
  [MBProgressHUDshowMessage:@""];
  [WebDataResponseInterfaceSessionManagerPostWebDataWithApi:WEBInterFace_Good_CreateWeiXinPayOrderandParameters:parameters andSuccess:^(id successObject) {
    MYLOG(@"%@", successObject);
    [MBProgressHUDhideHUD];
    if ([successObject[@"status"]isEqualToString:@"success"]) {
      successObject = [successObject objectForKey:@"value"];
      //     
      //          
      PayReq *req  = [[PayReqalloc] init];
      //       AppID       ,        
      req.openID = successObject[@"appid"];
      
      //   id,        
      req.partnerId = [successObjectobjectForKey:@"partnerid"];
      
      //                    ,             ,         
      req.prepayId = [successObjectobjectForKey:@"prepayid"];
      
      //                
      //      ,    ,    req.package = Sign=WXPay
      req.package  = [successObjectobjectForKey:@"package"];
      
      //     ,       ,     
      req.nonceStr = [successObjectobjectForKey:@"noncestr"];
      
      //       ,        ,       
      req.timeStamp = [[successObjectobjectForKey:@"timestamp"]doubleValue];
      
      //           
      req.sign = [successObjectobjectForKey:@"sign"];
      
      //       ,      onResp
      [WXApisendReq:req];
    } else {
      [MBProgressHUDshow:[successObject objectForKey:@"value"]icon:nilview:self.view];
    }
    
  } andFailure:^(NSError *error) {
    [MBProgressHUDhideHUD];
    MYLOG(@"error: %@", error);
  }];
}

궁금 한 점 이 있 으 시 면 메 시 지 를 남기 거나 본 사이트 의 커 뮤 니 티 에 가서 토론 을 하 세 요.읽 어 주 셔 서 감사합니다. 본문 을 통 해 여러분 을 도 울 수 있 기 를 바 랍 니 다.여러분 의 본 사이트 에 대한 지지 에 감 사 드 립 니 다!

좋은 웹페이지 즐겨찾기