Tag: PHP

jsonparsing在ios + php中

我在PHP中创build了具有1个参数的1个函数的web服务。 我使用phpMyadmin作为后端。 它使用json格式来获取数据。 Web服务正在完美运行。 我想在我的iPhone应用程序中使用这个Web服务。 我想传递1个参数。 我也提到了rayWenderlich教程也作为参考。 但找不到解决办法。 请帮我一下 这是我的networking服务代码: <?php echo getdata($_REQUEST['lastupdate']); function getdata($lastupdatedate){ $json = '{"foo-bar": 12345}'; $obj = json_decode($json); //print $obj->{'foo-bar'}; // 12345 $con = mysql_connect("localhost","un","Password"); if (!$con){ die('Could not connect: ' . mysql_error()); } //print_r($con); mysql_select_db("roster", $con); $query = "select * from rates where LastUpdated = '".$lastupdatedate."' order by LastUpdated limit […]

Objective-C版本的PHP mcrypt_encrypt

从四周search,我可以find一些链接引用类似的问题,但没有什么是相当的工作,其驱使我疯狂…. 有人可以请给我一步一步的指导如何在Objective C中编写下面的PHP代码 我们正在创build一些需要encryption内容的Web服务调用,而且我们只给了PHPencryption样本。 为了清楚我们不想取消encryption,我们想要在IOS中镜像这个encryption过程。 非常感谢 function encrypt($plainText) { $initVector = "mysite.com"; $key = base64_decode("GfSDfXS14U8I3YglEFrMjMOOnESUMxN3wRTt1TeDosY="); $block = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC); $padding = $block – (strlen($plainText) % $block); $plainText .= str_repeat(chr($padding), $padding); $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $plainText, MCRYPT_MODE_CBC, $initVector); $crypttext64 = base64_encode($crypttext); return $crypttext64; }

Objective-C POST请求不发送数据

我有一个方法,应该发布一些数据到PHP文件: -(void)submitForm { NSLog(@"name=%@", formName.text); // returns correct value NSString *post = [NSString stringWithFormat:@"name=%@&", formName.text]; NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; [request setURL:[NSURL URLWithString:@"http://path/to/file"]]; [request setHTTPMethod:@"POST"]; [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; [request setHTTPBody:postData]; NSURLResponse *response = NULL; NSError *requestError = NULL; […]

在生产模式下的推送通知不会到来但是在开发中即将到来

我的PNS在开发模式下工作良好。 我已经使用raywendelich博客做了这个。 同样的方式,我已经在生产模式下创build证书,并从服务器运行相同的脚本,但没有收到任何通知 当我们从我们的服务器进行生产模式testing时,需要哪个额外的步骤,是非常迫切的需要。 plase帮助生产模式做什么。 我们的PHP代码 <?php // Put your device token here (without spaces): $deviceToken = 'd5d89cab86e6f1a3cfa66dd853f3f4d7dd932c4a6da793cb9c86d31e9cfcb31f'; // Put your private key's passphrase here: $passphrase = '*******'; // Put your alert message here: $message = '****'; $ctx = stream_context_create(); stream_context_set_option($ctx, 'ssl', 'local_cert', 'ckm.pem'); stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase); // Open a connection to the APNS […]

如何从iOS发送的PHP中获取数组

以下是我的iOS代码发送NSmutablearrays到PHP的Web服务: // Getting Server Address AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; NSString *serverAddress = [appDelegate getServerAddress]; serverAddress = [serverAddress stringByAppendingString:@"ABC.php"]; NSLog(@"Server Address: %@",serverAddress); NSData *post = [NSJSONSerialization dataWithJSONObject:UsersArray options:NSJSONWritingPrettyPrinted error:nil]; NSString *postLength = [NSString stringWithFormat:@"%d", [post length]]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:serverAddress]]; [request setHTTPMethod:@"POST"]; [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; [request setHTTPBody:post]; [request […]

使用PHP在ios上通过JSON在web服务器上上传图片

我有一个在web服务器上传用户数据的应用程序。 我正在使用下面的代码将数据传递给Web服务器与下面的代码。 -(IBAction)btnRegister:(id)sender { jsonSP = [SBJSON new]; jsonSP.humanReadable = YES; NSString *service = @"/register.php"; NSData *imageData = UIImagePNGRepresentation([UIImage imageNamed:@"register_btn.png"]); [Base64 initialize]; NSString *imageString = [Base64 encode:imageData]; NSLog(@"%@",imageString); NSString *requestString = [NSString stringWithFormat:@"{\"?username\"=\"%@\"&\"user_password\"=\"%@\"&\"first_name\"=\"%@\"&\"email\"=\"%@\"&\"profile_photo_link\"=\"%@\"\"}",@"Test",@"Test",@"Test",@"Test@mmm.com",imageString]; NSData *requestData = [NSData dataWithBytes: [requestString UTF8String] length: [requestString length]]; NSString *fileLoc = [[NSBundle mainBundle] pathForResource:@"URLName" ofType:@"plist"]; NSDictionary *fileContents = [[NSDictionary alloc] […]

iOS推送通知不能使用PHP

我试图在iOS中使用APNS库实现推送通知。 这是我的代码: <?php // Put your device token here (without spaces): $deviceToken = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; // Put your private key's passphrase here: $passphrase = 'XXXXXX'; // Put your alert message here: $message = 'My first push notification!'; //////////////////////////////////////////////////////////////////////////////// $ctx = stream_context_create(); stream_context_set_option($ctx, 'ssl', 'local_cert', 'Certificates.pem'); stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase); // Open a connection to the APNS […]

Post从Swift到PHP的字典

如何在Swift中生成一个字典作为参数发布到PHP URL中? 具体来说,任务是更新托pipe数据库上的许多字段。 而不是为每个字段定义新的值作为一个单独的参数,我期待传递一个字典,其中的键是字段名称和值是新的值。 这个数据在Swift中已经作为一个Dictionary<String, String>存在了Dictionary<String, String>怎么能用下面的格式join到php url中: "http://server/directory/targetScript.php/?recordId=\(recId)&newFieldArray=\(itemDict)" 哪里: recId =正在更新的logging标识(作为与字典一起传递单独variables的示例) itemDict =在Swift中生成的字典 这是目前的代码: …它返回一个错误显示url为“零” class func updateItemInfo ( recordId:String, updatedDict:Dictionary<String, String> ) -> Void { //recordId = the FileMaker recordId of the item being updated //updatedDict = the primaryKey of the current item //direct to php file location let server:String = "myServer.com" let […]

Swift – 将base64编码的图像上传到php并显示图像

目前,我试图将一个base64编码的图像上传到一个PHP服务器,然后将base64string存储在MySQL数据库中。 目前,代码正在上传数据并将其存储到MySQL数据库中。 但是,当我尝试通过指定用于检索图像的URL来检索图像时,会显示一个缺less的带有问号的图像链接。 我不知道为什么会发生这种情况,因为上传和显示base64编码的图像似乎与我的Android应用程序正常工作。 这里是我用来编码和上传到服务器的Swift代码: let image: UIImage = imgProfilePic.image! let size = CGSizeApplyAffineTransform(image.size, CGAffineTransformMakeScale(0.3, 0.3)) let hasAlpha = false let scale: CGFloat = 0.0 // Automatically use scale factor of main screen UIGraphicsBeginImageContextWithOptions(size, !hasAlpha, scale) image.drawInRect(CGRect(origin: CGPointZero, size: size)) let scaledImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() var imageData = UIImageJPEGRepresentation(scaledImage, 0.9) var base64String = imageData.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0)) […]

如何在PHP中检查Apple AppReceipt服务器端的UID散列?

我问这个问题,以共享解决scheme的代码。 上下文:苹果在iOS 7中引入了AppReceipt。它也适用于OS X IAP。 这个收据是一个PKCS#7容器(asn.1),其有效负载也是asn.1结构化的。 Apple的文档指导如何控制设备收据的有效性,并parsing它以检查是否已经为当前设备发出。 还有联系Ap​​ple服务器通过应用程序服务器validation收据的说明。 不过,在后一种情况下,苹果公司返回的json数据不包含识别原始设备的信息。 之前的带有transactionReceipt的IAP协议模型在json中包含了identifierForVendor UID。 问题:如何使用PHPparsing服务器上的二进制收据以检查UID散列,以确保此收据属于此设备? 这可以在将收据发送到Apple服务器之前或之后完成。