TestImage.php 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * Alipay.com Inc.
  4. * Copyright (c) 2004-2014 All Rights Reserved.
  5. */
  6. include('../AlipayMobilePublicMultiMediaClient.php');
  7. header("Content-type: text/html; charset=gbk");
  8. /**
  9. *
  10. * @author wangYuanWai
  11. * @version $Id: Test.hp, v 0.1 Aug 6, 2014 4:20:17 PM yikai.hu Exp $
  12. */
  13. class TestImage
  14. {
  15. public $partner_public_key = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCitD16CypwZILTpdJL8nPV9rVFHYf5UWa/URNX6469mbQLpWfjKM/VSWRXsNVGSM3itOO/KG2Pw4x5g9xjH6iaE4LlaidjBIPpifISSlnpbyi4HxQTZYgMPv/TuiWofUN5kcwg/KQAQxB2OwTOeFu2i3LhqSCDmv6koTvHW15/hQIDAQAB";
  16. public $alipay_public_key = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDIgHnOn7LLILlKETd6BFRJ0GqgS2Y3mn1wMQmyh9zEyWlz5p1zrahRahbXAfCfSqshSNfqOmAQzSHRVjCqjsAw1jyqrXaPdKBmr90DIpIxmIyKXv4GGAkPyJ/6FTFY99uhpiq0qadD/uSzQsefWo0aTvP/65zi3eof7TcZ32oWpwIDAQAB";
  17. //公用变量
  18. public $serverUrl = 'http://publicexprod.d5336aqcn.alipay.net/chat/multimedia.do';//'http://publicexprod.d5336aqcn.alipay.net/chat/multimedia.do';//'http://i.com/works/photo-sdk/_data/1.jpg';//"http://i.com/works/photo-sdk/_data/publicexprod.php";//"http://publicexprod.d5336aqcn.alipay.net/chat/multimedia.do";
  19. public $appId = "2013121100055554";
  20. public $partner_private_key = 'MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAKK0PXoLKnBkgtOl0kvyc9X2tUUdh/lRZr9RE1frjr2ZtAulZ+Moz9VJZFew1UZIzeK0478obY/DjHmD3GMfqJoTguVqJ2MEg+mJ8hJKWelvKLgfFBNliAw+/9O6Jah9Q3mRzCD8pABDEHY7BM54W7aLcuGpIIOa/qShO8dbXn+FAgMBAAECgYA8+nQ380taiDEIBZPFZv7G6AmT97doV3u8pDQttVjv8lUqMDm5RyhtdW4n91xXVR3ko4rfr9UwFkflmufUNp9HU9bHIVQS+HWLsPv9GypdTSNNp+nDn4JExUtAakJxZmGhCu/WjHIUzCoBCn6viernVC2L37NL1N4zrR73lSCk2QJBAPb/UOmtSx+PnA/mimqnFMMP3SX6cQmnynz9+63JlLjXD8rowRD2Z03U41Qfy+RED3yANZXCrE1V6vghYVmASYsCQQCoomZpeNxAKuUJZp+VaWi4WQeMW1KCK3aljaKLMZ57yb5Bsu+P3odyBk1AvYIPvdajAJiiikRdIDmi58dqfN0vAkEAjFX8LwjbCg+aaB5gvsA3t6ynxhBJcWb4UZQtD0zdRzhKLMuaBn05rKssjnuSaRuSgPaHe5OkOjx6yIiOuz98iQJAXIDpSMYhm5lsFiITPDScWzOLLnUR55HL/biaB1zqoODj2so7G2JoTiYiznamF9h9GuFC2TablbINq80U2NcxxQJBAMhw06Ha/U7qTjtAmr2qAuWSWvHU4ANu2h0RxYlKTpmWgO0f47jCOQhdC3T/RK7f38c7q8uPyi35eZ7S1e/PznY=';
  21. public $format = "json";
  22. public $charset = "GBK";
  23. function __construct()
  24. {
  25. }
  26. public function load()
  27. {
  28. $alipayClient = new AlipayMobilePublicMultiMediaClient(
  29. $this->serverUrl,
  30. $this->appId,
  31. $this->partner_private_key,
  32. $this->format,
  33. $this->charset
  34. );
  35. $response = null;
  36. $outputStream = null;
  37. $request = $alipayClient->getContents();
  38. //200
  39. //echo( '状态码:'. $request -> getCode() .', ');
  40. //echo '<hr /><br /><br /><br />';
  41. $fileType = $request->getType();
  42. //echo( '类型:'. $fileType .', ');
  43. if ($fileType == 'text/plain') {
  44. //出错,返回 json
  45. echo $request->getBody();
  46. } else {
  47. $type = $request->getFileSuffix($fileType);
  48. //echo $this -> getParams();
  49. //exit();
  50. //返回 文件流
  51. header("Content-type: " . $fileType); //类型
  52. header("Accept-Ranges: bytes");//告诉客户端浏览器返回的文件大小是按照字节进行计算的
  53. header("Accept-Length: " . $request->getContentLength());//文件大小
  54. header("Content-Length: " . $request->getContentLength());//文件大小
  55. header('Content-Disposition: attachment; filename="' . time() . '.' . $type . '"'); //文件名
  56. echo $request->getBody();
  57. exit ();
  58. }
  59. //echo( '内容: , '. $request -> getContentLength() );
  60. //echo '<hr /><br /><br /><br />';
  61. //echo '参数:<pre>';
  62. //echo ($request -> getParams());
  63. //echo '</pre>' ;
  64. }
  65. }
  66. // 测试
  67. $test1 = new TestImage();
  68. $test1->load();