国内流行的内容管理系统(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.

192 lines
6.5KB

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