IOS 통합 위 챗 결제 기능 의 실현 방법
5728 단어 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);
}];
}
궁금 한 점 이 있 으 시 면 메 시 지 를 남기 거나 본 사이트 의 커 뮤 니 티 에 가서 토론 을 하 세 요.읽 어 주 셔 서 감사합니다. 본문 을 통 해 여러분 을 도 울 수 있 기 를 바 랍 니 다.여러분 의 본 사이트 에 대한 지지 에 감 사 드 립 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
IOS에서 ReplayKit 및 RTC 사용 방법응용된 소리와 아나운서의 소리를 포함한다.이 두 가지 수요를 감안하여 우리는 스크린 공유를 하는 생방송에 필요한 미디어 흐름을 간단하게 분석할 수 있다. 만약 우리가 Audio App과 Audio Mic를 두 개의 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.