Pdx.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. if( !defined('BASEPATH') )
  3. {
  4. exit( 'No direct script access allowed' );
  5. }
  6. class Pays_app
  7. {
  8. public function __construct()
  9. {
  10. if( CT_Pay == 0 )
  11. {
  12. msg_url("在线支付功能已关闭~!", "javascript:history.back();");
  13. }
  14. $this->api_url = "http://";
  15. if( Web_Mode == 2 )
  16. {
  17. $this->return_url = "http://" . Web_Url . Web_Path . "index.php?d=app&c=pay&m=return_url";
  18. $this->notify_url = "http://" . Web_Url . Web_Path . "index.php?d=app&c=pay&m=notify_url";
  19. }
  20. else
  21. {
  22. $this->return_url = "http://" . Web_Url . Web_Path . "index.php/app/pay/return_url";
  23. $this->notify_url = "http://" . Web_Url . Web_Path . "index.php/app/pay/notify_url";
  24. }
  25. }
  26. public function to($row = array( ), $mid = 0)
  27. {
  28. $body = ($row["cid"] == 0 ? "会员在线购买金币" : "会员在线购买Vip");
  29. $sign_arr = array( "pay_sid" => $row["sid"] + 1, "out_trade_no" => $row["dingdan"], "total_fee" => (double) $row["rmb"], "partner" => CT_Pay_ID, "return_url" => $this->return_url, "notify_url" => $this->notify_url );
  30. $sign = $this->md5_sign($sign_arr, CT_Pay_Key);
  31. $parameter = $sign_arr;
  32. $parameter["charset"] = "utf-8";
  33. $parameter["body"] = urlencode($body);
  34. $parameter["sign"] = $sign;
  35. $parameter["mid"] = $mid;
  36. return $this->api_url . "?" . $this->arr_url($parameter);
  37. }
  38. public function md5_sign($arr, $skey)
  39. {
  40. $arr_filter = array( );
  41. foreach( $arr as $key => $val )
  42. {
  43. if( $key == "sign" || $val == "" )
  44. {
  45. continue;
  46. }
  47. $arr_filter[$key] = $arr[$key];
  48. }
  49. ksort($arr_filter);
  50. reset($arr_filter);
  51. $arg = "";
  52. foreach( $arr_filter as $key => $val )
  53. {
  54. $arg .= $key . "=" . urlencode($val) . "&";
  55. }
  56. $arg = substr($arg, 0, count($arg) - 2);
  57. if( get_magic_quotes_gpc() )
  58. {
  59. $arg = stripslashes($arg);
  60. }
  61. $sign = strtoupper(md5($arg . $skey));
  62. return $sign;
  63. }
  64. }