国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

193 lines
6.6KB

  1. <?php
  2. /**
  3. * @version $Id: buy_action.php 1 8:38 2010年7月9日Z tianya $
  4. * @package DedeCMS.Member
  5. * @copyright Copyright (c) 2007 - 2018, DesDev, Inc.
  6. * @copyright Copyright (c) 2020, DedeBIZ.COM
  7. * @license https://www.dedebiz.com/license/v6
  8. * @link https://www.dedebiz.com
  9. */
  10. require_once(dirname(__FILE__) . "/config.php");
  11. CheckRank(0, 0);
  12. $menutype = 'mydede';
  13. $menutype_son = 'op';
  14. require_once DEDEINC . '/dedetemplate.class.php';
  15. $product = isset($product) ? trim(HtmlReplace($product, 1)) : '';
  16. $mid = $cfg_ml->M_ID;
  17. $ptype = '';
  18. $pname = '';
  19. $price = '';
  20. $mtime = time();
  21. if (isset($pd_encode) && isset($pd_verify) && md5("payment" . $pd_encode . $cfg_cookie_encode) == $pd_verify) {
  22. $result = json_decode(mchStrCode($pd_encode, 'DECODE'));
  23. $product = preg_replace("#[^0-9a-z]#i", "", $result->product);
  24. $pid = preg_replace("#[^0-9a-z]#i", "", $result->pid);
  25. $row = $dsql->GetOne("SELECT * FROM `#@__member_operation` WHERE mid='$mid' AND sta=0 AND product='$product'");
  26. if (!isset($row['buyid'])) {
  27. ShowMsg("请不要重复提交表单!", 'javascript:;');
  28. exit();
  29. }
  30. if (!isset($paytype)) {
  31. ShowMsg("请选择支付方式!", 'javascript:;');
  32. exit();
  33. }
  34. $buyid = $row['buyid'];
  35. } else {
  36. $buyid = 'M' . $mid . 'T' . $mtime . 'RN' . mt_rand(100, 999);
  37. //删除用户旧的未付款的同类记录
  38. if (!empty($product)) {
  39. $dsql->ExecuteNoneQuery("DELETE FROM `#@__member_operation` WHERE mid='$mid' AND sta=0 AND product='$product'");
  40. }
  41. }
  42. if (empty($product)) {
  43. ShowMsg("请选择一个产品!", 'javascript:;');
  44. exit();
  45. }
  46. $pid = isset($pid) && is_numeric($pid) ? $pid : 0;
  47. if ($product == 'member') {
  48. $ptype = "会员升级";
  49. $row = $dsql->GetOne("SELECT * FROM `#@__member_type` WHERE aid='{$pid}'");
  50. if (!is_array($row)) {
  51. ShowMsg("无法识别你的订单!", 'javascript:;');
  52. exit();
  53. }
  54. $pname = $row['pname'];
  55. $price = $row['money'];
  56. } else if ($product == 'card') {
  57. $ptype = "点卡购买";
  58. $row = $dsql->GetOne("SELECT * From `#@__moneycard_type` WHERE tid='{$pid}'");
  59. if (!is_array($row)) {
  60. ShowMsg("无法识别你的订单!", 'javascript:;');
  61. exit();
  62. }
  63. $pname = $row['pname'];
  64. $price = $row['money'];
  65. }
  66. if (!isset($paytype)) {
  67. $inquery = "INSERT INTO `#@__member_operation`(`buyid` , `pname` , `product` , `money` , `mtime` , `pid` , `mid` , `sta` ,`oldinfo`)
  68. VALUES ('$buyid', '$pname', '$product' , '$price' , '$mtime' , '$pid' , '$mid' , '0' , '$ptype');
  69. ";
  70. $isok = $dsql->ExecuteNoneQuery($inquery);
  71. if (!$isok) {
  72. echo "数据库出错,请重新尝试!" . $dsql->GetError();
  73. exit();
  74. }
  75. if ($price == '') {
  76. echo "无法识别你的订单!";
  77. exit();
  78. }
  79. //获取支付接口列表
  80. $payment_list = array();
  81. $dsql->SetQuery("SELECT * FROM `#@__payment` WHERE enabled='1' ORDER BY rank ASC");
  82. $dsql->Execute();
  83. $i = 0;
  84. while ($row = $dsql->GetArray()) {
  85. $payment_list[] = $row;
  86. $i++;
  87. }
  88. unset($row);
  89. $pr_encode = array();
  90. foreach ($_REQUEST as $key => $val) {
  91. if (!in_array($key, array('product', 'pid'))) {
  92. continue;
  93. }
  94. $val = preg_replace("#[^0-9a-z]#i", "", $val);
  95. $pr_encode[$key] = $val;
  96. }
  97. $pr_encode = str_replace('=', '', mchStrCode(json_encode($pr_encode)));
  98. $pr_verify = md5("payment" . $pr_encode . $cfg_cookie_encode);
  99. $tpl = new DedeTemplate();
  100. $tpl->LoadTemplate(DEDEMEMBER . '/templets/buy_action_payment.htm');
  101. $tpl->Display();
  102. } else {
  103. $rs = $dsql->GetOne("SELECT * FROM `#@__payment` WHERE id='$paytype' ");
  104. $rs['code'] = preg_replace("#[^0-9a-z]#i", "", $rs['code']);
  105. if (!file_exists(DEDEINC . '/payment/' . $rs['code'] . '.php')) {
  106. ShowMsg("未发现支付接口文件,请到后台配置!", 'javascript:;');
  107. exit();
  108. }
  109. require_once DEDEINC . '/payment/' . $rs['code'] . '.php';
  110. $pay = new $rs['code'];
  111. $payment = "";
  112. if ($rs['code'] == "cod" || $rs['code'] == "bank") {
  113. $order = $buyid;
  114. $payment = "member";
  115. } else {
  116. $order = array(
  117. 'out_trade_no' => $buyid,
  118. 'price' => sprintf("%01.2f", $price)
  119. );
  120. require_once DEDEDATA . '/payment/' . $rs['code'] . '.php';
  121. }
  122. $button = $pay->GetCode($order, $payment);
  123. $dtp = new DedeTemplate();
  124. $carts = array(
  125. 'orders_id' => $buyid,
  126. 'cart_count' => '1',
  127. 'price_count' => sprintf("%01.2f", $price)
  128. );
  129. $row = $dsql->GetOne("SELECT pname,money FROM `#@__member_operation` WHERE buyid='{$buyid}'");
  130. $dtp->SetVar('pay_name', $row['pname']);
  131. $dtp->SetVar('price', $row['money']);
  132. $dtp->SetVar('pay_way', $rs['name']);
  133. $dtp->SetVar('description', $rs['description']);
  134. $dtp->SetVar('button', $button);
  135. $dtp->Assign('carts', $carts);
  136. $dtp->LoadTemplate(DEDEMEMBER . '/templets/shops_action_payment.htm');
  137. $dtp->Display();
  138. exit();
  139. }
  140. /**
  141. * 加密函数
  142. *
  143. * @access public
  144. * @param string $string 字符串
  145. * @param string $operation 操作
  146. * @return string
  147. */
  148. function mchStrCode($string, $operation = 'ENCODE')
  149. {
  150. $key_length = 4;
  151. $expiry = 0;
  152. $key = md5($GLOBALS['cfg_cookie_encode']);
  153. $fixedkey = md5($key);
  154. $egiskeys = md5(substr($fixedkey, 16, 16));
  155. $runtokey = $key_length ? ($operation == 'ENCODE' ? substr(md5(microtime(true)), -$key_length) : substr($string, 0, $key_length)) : '';
  156. $keys = md5(substr($runtokey, 0, 16) . substr($fixedkey, 0, 16) . substr($runtokey, 16) . substr($fixedkey, 16));
  157. $string = $operation == 'ENCODE' ? sprintf('%010d', $expiry ? $expiry + time() : 0) . substr(md5($string . $egiskeys), 0, 16) . $string : base64_decode(substr($string, $key_length));
  158. $i = 0;
  159. $result = '';
  160. $string_length = strlen($string);
  161. for ($i = 0; $i < $string_length; $i++) {
  162. $result .= chr(ord($string[$i]) ^ ord($keys[$i % 32]));
  163. }
  164. if ($operation == 'ENCODE') {
  165. return $runtokey . str_replace('=', '', base64_encode($result));
  166. } else {
  167. if ((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26) . $egiskeys), 0, 16)) {
  168. return substr($result, 26);
  169. } else {
  170. return '';
  171. }
  172. }
  173. }