pay_abstract.class.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. abstract class paymentabstract
  3. {
  4. protected $config = array();
  5. protected $product_info = array();
  6. protected $customter_info = array();
  7. protected $order_info = array();
  8. protected $shipping_info = array();
  9. public function set_config($config)
  10. {
  11. foreach ($config as $key => $value) $this->config[$key] = $value;
  12. return $this;
  13. }
  14. public function set_productinfo($product_info)
  15. {
  16. $this->product_info = $product_info;
  17. return $this;
  18. }
  19. public function set_customerinfo($customer_info)
  20. {
  21. $this->customer_info = $customer_info;
  22. return $this;
  23. }
  24. public function set_orderinfo($order_info)
  25. {
  26. $this->order_info = $order_info;
  27. return $this;
  28. }
  29. public function set_shippinginfo($shipping_info)
  30. {
  31. $this->shipping_info = $shipping_info;
  32. return $this;
  33. }
  34. public function get_code($button_attr = '')
  35. {
  36. if (strtoupper($this->config['gateway_method']) == 'POST') $str = '<form action="' . $this->config['gateway_url'] . '" method="POST" target="_blank">';
  37. else $str = '<form action="' . $this->config['gateway_url'] . '" method="GET" target="_blank">';
  38. $prepare_data = $this->getpreparedata();
  39. foreach ($prepare_data as $key => $value) $str .= '<input type="hidden" name="' . $key . '" value="' . $value . '" />';
  40. $str .= '<input type="submit" ' . $button_attr . ' />';
  41. $str .= '</form>';
  42. return $str;
  43. }
  44. protected function get_verify($url,$time_out = "60") {
  45. $urlarr = parse_url($url);
  46. $errno = "";
  47. $errstr = "";
  48. $transports = "";
  49. if($urlarr["scheme"] == "https") {
  50. $transports = "ssl://";
  51. $urlarr["port"] = "443";
  52. } else {
  53. $transports = "tcp://";
  54. $urlarr["port"] = "80";
  55. }
  56. $fp=@fsockopen($transports . $urlarr['host'],$urlarr['port'],$errno,$errstr,$time_out);
  57. if(!$fp) {
  58. die("ERROR: $errno - $errstr<br />\n");
  59. } else {
  60. fputs($fp, "POST ".$urlarr["path"]." HTTP/1.1\r\n");
  61. fputs($fp, "Host: ".$urlarr["host"]."\r\n");
  62. fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
  63. fputs($fp, "Content-length: ".strlen($urlarr["query"])."\r\n");
  64. fputs($fp, "Connection: close\r\n\r\n");
  65. fputs($fp, $urlarr["query"] . "\r\n\r\n");
  66. while(!feof($fp)) {
  67. $info[]=@fgets($fp, 1024);
  68. }
  69. fclose($fp);
  70. $info = implode(",",$info);
  71. return $info;
  72. }
  73. }
  74. abstract public function receive();
  75. abstract public function notify();
  76. abstract public function response($result);
  77. abstract public function getPrepareData();
  78. }