0
我已經集成了payumoney支付網關。我能夠用密鑰創建正確的哈希值,但最終得到一條警告消息,因爲「密鑰無效」,那會是什麼問題?iOS Payumoney SDK密鑰無效
這是代碼。我使用鏈接「https://www.payumoney.com/payment-gateway-integration-guide.html」下載payumoney SDK。
- (IBAction)startPaymentTapped:(id)sender {
[self setPaymentParameters];
//Start the payment flow
PUMMainVController *paymentVC = [[PUMMainVController alloc] init];
UINavigationController *paymentNavController = [[UINavigationController alloc] initWithRootViewController:paymentVC];
[self presentViewController:paymentNavController
animated:YES
completion:nil];
}
- (void)setPaymentParameters {
self.params = [PUMRequestParams sharedParams];
self.params.environment = PUMEnvironmentProduction;
self.params.amount = self.amount.text;
self.params.key = @"mykeyvalue";
self.params.merchantid = @"merchantid";
self.params.txnid = [self getRandomString:2];
self.params.surl = @"https://www.payumoney.com/mobileapp/payumoney/success.php";
self.params.furl = @"https://www.payumoney.com/mobileapp/payumoney/failure.php";
self.params.delegate = self;
self.params.firstname = self.firstname.text;
self.params.productinfo = self.productinfo.text;
self.params.email = self.email.text;
self.params.phone = @"";
self.params.udf1 = @"";
self.params.udf2 = @"";
self.params.udf3 = @"";
self.params.udf4 = @"";
self.params.udf5 = @"";
self.params.udf6 = @"";
self.params.udf7 = @"";
self.params.udf8 = @"";
self.params.udf9 = @"";
self.params.udf10 = @"";
self.params.hashValue = [self getHash];
}
- (NSString *)getRandomString:(NSInteger)length {
NSMutableString *returnString = [NSMutableString stringWithCapacity:length];
NSString *numbers = @"";
// First number cannot be 0
[returnString appendFormat:@"%C", [numbers characterAtIndex:(arc4random() % ([numbers length]-1))+1]];
for (int i = 1; i < length; i++) {
[returnString appendFormat:@"%C", [numbers characterAtIndex:arc4random() % [numbers length]]];
}
return returnString;
}
- (NSString*)getHash {
NSString *hashSequence = [NSString stringWithFormat:@"mykeyvalue|%@|%@|%@|%@|%@|||||||||||salt",self.params.txnid, self.params.amount, self.params.productinfo,self.params.firstname, self.params.email];
NSString *rawHash = [[self createSHA512:hashSequence] description];
NSString *hash = [[[rawHash stringByReplacingOccurrencesOfString:@"<" withString:@""]stringByReplacingOccurrencesOfString:@">" withString:@""]stringByReplacingOccurrencesOfString:@" " withString:@""];
return hash;
}
- (NSData *) createSHA512:(NSString *)source {
const char *s = [source cStringUsingEncoding:NSASCIIStringEncoding];
NSData *keyData = [NSData dataWithBytes:s length:strlen(s)];
uint8_t digest[CC_SHA512_DIGEST_LENGTH] = {0};
CC_SHA512(keyData.bytes, (CC_LONG)keyData.length, digest);
NSData *output = [NSData dataWithBytes:digest length:CC_SHA512_DIGEST_LENGTH];
NSLog(@"out --------- %@",output);
return output;
}
你在這兩個地方通過的密鑰'self.params.key = @「mykeyvalue」; self.params.merchantid = @「merchantid」;' –
我從服務器團隊獲得的數據,例如: self.params.key @「mdyCKV」; self.params.merchantid = @「4914106」; [虛擬值] –