国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

iOS開發日記3-微信支付

2019-11-14 18:31:07
字體:
來源:轉載
供稿:網友

今天博主有一個微信支付的需求,遇到了一些困難點,在此和大家分享,希望能夠共同進步.

1.申請AppID,導入依賴庫,配置URL Scheme這里就不深究了,各位看官請自行百度.

2.在AppDelegate中導入頭文件,遵守WXApiDelegate,然后在launch里注冊AppID.

3.在支付界面導入頭文件,創建支付對象,調起微信

//調起微信支付,傳入參數

PayReq* req = [[[PayReq alloc] init]autorelease];

req.openID = APPI_ID;

req.partnerId = PARTNER_ID;

req.PRepayId = prePayid;

req.nonceStr = nonce_str;

req.timeStamp = now;

req.package = package;

req.sign = sign;

[WXApi safeSendReq:req];

4.微信支付的回調需要添加在AppDelegate中

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation

{

 

     //返回應用后的回調,通過handleOpenURL進入微信支付的回調onResp:(BaseResp*)resp

         return [WXApi handleOpenURL:url delegate:self];

}

-(void) onResp:(BaseResp*)resp

{

if ([resp isKindOfClass:[PayResp class]])

{

PayResp *response = (PayResp *)resp;

NSString *strTitle = [NSString stringWithFormat:@"支付結果"];

NSString *strMsg = [NSString stringWithFormat:@"errcode:%d", response.errCode];

 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:strTitlemessage:strMsg  delegate:self cancelButtonTitle:@"OK"  otherButtonTitles:nil, nil];

[alert show];

switch (response.errCode) {

case WXSuccess: {

NSNotification *notification = [NSNotification notificationWithName:ORDER_PAY_NOTIFICATION object:@"success"];

[[NSNotificationCenter defaultCenter] postNotification:notification];

break;

}

default: {

NSNotification *notification = [NSNotification notificationWithName:ORDER_PAY_NOTIFICATION object:@"fail"];

[[NSNotificationCenter defaultCenter] postNotification:notification];

break;

}

}

}

}

但是將微信支付相關的代碼全部寫到AppDelegate中又會顯得代碼冗余,這時我們需要創建通知,在成功回調后發出通知,在支付界面監聽回調,完成支付.

5.在監聽回調中,上傳我們從微信支付中獲得的參數,完成支付.

 

http://www.jianshu.com/p/97d38b00e53d?plg_nld=1&plg_auth=1&plg_nld=1&plg_dev=1&plg_uin=1&plg_usr=1&plg_vkey=1&plg_nld=1&plg_uin=1&plg_nld=1&plg_auth=1&plg_usr=1&plg_vkey=1&plg_dev=1

 

http://www.tuicool.com/articles/32UFBzQ?plg_nld=1&plg_uin=1&plg_auth=1&plg_nld=1&plg_usr=1&plg_vkey=1&plg_dev=1

 

http://www.jianshu.com/p/6e75a450dcc4?plg_nld=1&plg_uin=1&plg_auth=1&plg_nld=1&plg_usr=1&plg_vkey=1&plg_dev=1


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 湘潭市| 台前县| 吉林省| 湘潭市| 大同县| 大足县| 安溪县| 慈溪市| 蒲江县| 丁青县| 买车| 额济纳旗| 昆山市| 罗田县| 来宾市| 丹寨县| 衡阳县| 清徐县| 杂多县| 白朗县| 茂名市| 江陵县| 鸡东县| 天门市| 措勤县| 乌兰浩特市| 夹江县| 漳州市| 古蔺县| 北碚区| 什邡市| 垦利县| 德安县| 兖州市| 时尚| 镇安县| 高阳县| 堆龙德庆县| 丹阳市| 社会| 射阳县|