国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

206 wiersze
6.5KB

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