https://www.baidu.com/s?wd=%E6%94%AF%E4%BB%98%E5%AE%9D%E5%BC%80%E5%8F%91%E8%80%85%E5%B9%B3%E5%8F%B0&rsv_spt=1&rsv_iqid=0xfe0a29290002df6b&issp=1&f=3&rsv_bp=0&rsv_idx=2&ie=utf-8&tn=monline_3_dg&rsv_enter=1&rsv_sug3=14&rsv_sug1=10&rsv_sug7=100&rsv_sug2=0&prefixsug=%E6%94%AF%E4%BB%98%E5%AE%9D%E9%9B%86%E6%88%90&rsp=4&inputT=9885&rsv_sug4=10467
https://doc.open.alipay.com/
long activityId = _activitiy.ActivityId;
NSString *stringActivityId = [@(activityId) stringValue]; //活动ID
NSString *userId = [AppConfig shareInstance].UserID;
//用户ID
[self.paramDic setObject:stringActivityId forKey:@"activityId"];
[self.paramDic setObject:userId forKey:@"userId"];
NSString *bodyStr = _activitiy.title;
NSString *subjectStr = _activitiy.title;
NSInteger total_amount = _activitiy.totalFee;
NSDateFormatter* formatter = [NSDateFormatter new];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDictionary *lastDic = @{
@"body":bodyStr,
@"subject":subjectStr,
@"total_amount":[NSString stringWithFormat:@"%.2ld",(long)total_amount],
@"spbillCreateip":[self deviceIPAdress]
};
NSMutableDictionary *bigDic = [lastDic mutableCopy];
[bigDic addEntriesFromDictionary:dic];
[[[SpeedService alloc]init]FetchUserPayProduct:nil paramDic:bigDic completionBlock:^(id response, NSError *error) {
NSLog(@"++++%@",response);
//服务器返回的订单信息
NSDictionary *samllDic = [response objectForKey:@"result"];
//服务器返回的签名
NSString *sign = [samllDic objectForKey:@"sign"];
//签名Encode编码
NSString *locationSignEncode = [self encodeValue:sign];
//创建订单模型对象并且赋值
Order *order = [Order new];
order.biz_content = [BizContent new];
order.app_id = [samllDic objectForKey:@"app_id"];
order.biz_content = [samllDic objectForKey:@"biz_content"];
order.charset = [samllDic objectForKey:@"charset"];
order.method = [samllDic objectForKey:@"method"];
order.notify_url = [samllDic objectForKey:@"notify_url"];
order.sign_type = [samllDic objectForKey:@"sign_type"];
order.timestamp = [samllDic objectForKey:@"timestamp"];
order.version = [samllDic objectForKey:@"version"];
//订单信息Encode编码
NSString *messageEncode = [order orderInfoEncoded:YES];
//最终订单信息字符串Encode编码
NSString *orderOneString = [NSString stringWithFormat:@"%@&sign=%@",
messageEncode, locationSignEncode];
[[AlipaySDK defaultService] payOrder:orderOneString fromScheme:Scheme callback:^(NSDictionary *resultDic) {
NSLog(@"服务器返回的结果:%@",resultDic);
}];
}];
- (NSString*)encodeValue:(NSString*)value
{
NSString* encodedValue = value;
if (value.length > 0) {
encodedValue = (__bridge_transfer NSString*)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (__bridge CFStringRef)value, NULL, (__bridge CFStringRef)@"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8 );
}
return encodedValue;
}
[微信支付]APP支付开发者文档
https://www.baidu.com/s?wd=%E5%BE%AE%E4%BF%A1%E6%94%AF%E4%BB%98%E5%B9%B3%E5%8F%B0&rsv_spt=1&rsv_iqid=0x970a0db100003d17&issp=1&f=3&rsv_bp=0&rsv_idx=2&ie=utf-8&tn=monline_3_dg&rsv_enter=1&rsv_sug3=12&rsv_sug1=9&rsv_sug7=100&rsv_sug2=0&prefixsug=%E5%BE%AE%E4%BF%A1%E6%94%AF%E4%BB%98&rsp=8&inputT=7099&rsv_sug4=7846
https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=11_1
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[WXApi registerApp:WXapp_id withDescription:@"测试demo"];
}
#pragma mark - 微信支付
- (void)setUpWxPay
{
long activityId = _activitiy.ActivityId;
NSString *stringActivityId = [@(activityId) stringValue];
NSString *userId = [AppConfig shareInstance].UserID;
NSString *userTel = [self.paramDic objectForKey:@"mobile"];
if (userTel.length == 0 || userTel.length > 11) {
[SVProgressHUD showErrorWithStatus:@"请输入正确的联系电话"];
return;
}
NSString *userName = [self.paramDic objectForKey:@"name"];
if (userName.length == 0) {
[SVProgressHUD showErrorWithStatus:@"请输入姓名"];
return;
}
NSString *userIdentity = [self.paramDic objectForKey:@"identity"];
BOOL identity = [self isCorrect:userIdentity];
NSString *userEmail = [self.paramDic objectForKey:@"email"];
if (userEmail.length == 0) {
[SVProgressHUD showErrorWithStatus:@"请输入邮箱号"];
return;
}
NSInteger totalFee = _activitiy.totalFee;
NSString *body = _activitiy.title;
NSString *subject = _activitiy.title;
NSString *spbillCreateip = [self deviceIPAdress];
SpeedService *speedService = [[SpeedService alloc] init];
NSDictionary *dict = @{
@"body":body,
@"subject":subject,
@"userId":userId,
@"activityId":stringActivityId,
@"name":userName,
@"email":userEmail,
@"mobile":userTel,
@"identity":userIdentity,
@"total_amount":[NSString stringWithFormat:@"%d",totalFee],
@"spbillCreateip":spbillCreateip
};
NSLog(@"字典是 : %@",dict);
if (identity == YES) {
//判断是否安装了微信
if ([WXApi isWXAppInstalled]){
[speedService FetchUserWxPayProduct:dict completionBlock:^(id response, NSError *error) {
if (!error) {
NSLog(@"返回的结果是 : %@",response);
NSString * str = [response objectForKey:@"code"];
if ([str isEqualToString:@"0000"]) {
NSDictionary *dic = [NSDictionary dictionaryWithDictionary:[response objectForKey:@"result"]];
[self configRequest:dic stringStr:nil];
}
}else{
NSLog(@"网络超时,返回的错误信息是 : %@",error);
}
}];
}else{
[SVProgressHUD showErrorWithStatus:@"请安装微信"];
}
}else{
[SVProgressHUD showErrorWithStatus:@"请输入正确的身份证号码"];
return;
}
}
#pragma mark - 调用微信支付的接口
- (void)configRequest:(NSDictionary *)dic stringStr:(NSString *)stringStr{
//需要创建这个支付对象
PayReq *req = [[PayReq alloc] init];
//由用户微信号和AppID组成的唯一标识,用于校验微信用户
req.openID = [dic objectForKey:@"appid"];
// 商家id,在注册的时候给的
req.partnerId = [dic objectForKey:@"partnerid"];
// 预支付订单这个是后台跟微信服务器交互后,微信服务器传给你们服务器的,你们服务器再传给你
req.prepayId = [dic objectForKey:@"prepayid"];
// 随机编码,为了防止重复的,在后台生成
req.nonceStr = [dic objectForKey:@"noncestr"];
// 这个是时间戳,也是在后台生成的,为了验证支付的
NSMutableString *stamp = [dic objectForKey:@"timestamp"];
req.timeStamp = stamp.intValue;
// 根据财付通文档填写的数据和签名
//这个比较特殊,是固定的,只能是即req.package = Sign=WXPay
req.package = [dic objectForKey:@"package"];
// 这个签名也是后台做的
req.sign = [dic objectForKey:@"sign"];
//发送请求到微信,等待微信返回onResp
[WXApi sendReq:req];
}