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

buy_action.php 11KB

3 年之前
2 年之前
3 年之前
3 年之前
2 年之前
2 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <?php
  2. /**
  3. * @version $id:buy_action.php 8:38 2023年02月13日 tianya $
  4. * @package DedeBIZ.User
  5. * @copyright Copyright (c) 2022 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. $dopost = isset($dopost)? $dopost : '';
  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. $paytype = isset($paytype)? intval($paytype) : 0;
  22. if ($dopost === "bank_ok") {
  23. $moRow = $dsql->GetOne("SELECT * FROM `#@__member_operation` WHERE buyid='$buyid' AND mid={$mid}");
  24. if (empty($moRow)) {
  25. ShowMsg("订单查询错误,请确保是您自己发起的订单", "javascript:;");
  26. exit;
  27. }
  28. if ($moRow['sta'] == 2) {
  29. ShowMsg("已完成支付,无需重复付款", "javascript:;");
  30. exit;
  31. }
  32. $query = "UPDATE `#@__member_operation` SET sta = '1' WHERE buyid = '{$moRow['buyid']}'";
  33. $dsql->ExecuteNoneQuery($query);
  34. ShowMsg("已经完成付款,等待管理员审核", "operation.php");
  35. exit;
  36. }
  37. if (isset($pd_encode) && isset($pd_verify) && md5("payment".$pd_encode.$cfg_cookie_encode) == $pd_verify) {
  38. $result = json_decode(mchStrCode($pd_encode, 'DECODE'));
  39. $product = preg_replace("#[^0-9a-z]#i", "", $result->product);
  40. $pid = preg_replace("#[^0-9a-z]#i", "", $result->pid);
  41. $row = $dsql->GetOne("SELECT * FROM `#@__member_operation` WHERE mid='$mid' AND sta=0 AND product='$product'");
  42. if (!isset($row['buyid'])) {
  43. ShowMsg("请不要重复提交表单", 'javascript:;');
  44. exit();
  45. }
  46. if ($paytype === 0) {
  47. ShowMsg("请选择支付方式", 'javascript:;');
  48. exit();
  49. }
  50. $buyid = $row['buyid'];
  51. } else {
  52. $buyid = 'M'.$mid.'T'.$mtime.'RN'.mt_rand(100, 999);
  53. //删除用户旧的未付款的同类记录
  54. if (!empty($product)) {
  55. $dsql->ExecuteNoneQuery("DELETE FROM `#@__member_operation` WHERE mid='$mid' AND sta=0 AND product='$product'");
  56. }
  57. }
  58. if (empty($product)) {
  59. ShowMsg("请选择一个产品", 'javascript:;');
  60. exit();
  61. }
  62. $pid = isset($pid) && is_numeric($pid) ? $pid : 0;
  63. if ($product == 'member') {
  64. $ptype = "会员升级";
  65. $row = $dsql->GetOne("SELECT * FROM `#@__member_type` WHERE aid='{$pid}'");
  66. if (!is_array($row)) {
  67. ShowMsg("无法识别您的订单", 'javascript:;');
  68. exit();
  69. }
  70. $pname = $row['pname'];
  71. $price = $row['money'];
  72. } else if ($product == 'card') {
  73. $ptype = "积分购买";
  74. $row = $dsql->GetOne("SELECT * FROM `#@__moneycard_type` WHERE tid='{$pid}'");
  75. if (!is_array($row)) {
  76. ShowMsg("无法识别您的订单", 'javascript:;');
  77. exit();
  78. }
  79. $pname = $row['pname'];
  80. $price = $row['money'];
  81. }
  82. if ($paytype === 0) {
  83. $inquery = "INSERT INTO `#@__member_operation` (`buyid`,`pname`,`product`,`money`,`mtime`,`pid`,`mid`,`sta`,`oldinfo`) VALUES ('$buyid','$pname','$product','$price','$mtime','$pid','$mid','0','$ptype');";
  84. $isok = $dsql->ExecuteNoneQuery($inquery);
  85. if (!$isok) {
  86. echo "数据库出错,请重新尝试".$dsql->GetError();
  87. exit();
  88. }
  89. if ($price == '') {
  90. echo "无法识别您的订单";
  91. exit();
  92. }
  93. //获取支付接口设置
  94. $payment_list = array();
  95. $dsql->SetQuery("SELECT * FROM `#@__sys_payment` WHERE `status`=1 ORDER BY sortrank ASC");
  96. $dsql->Execute();
  97. $i = 0;
  98. while ($row = $dsql->GetArray()) {
  99. $payment_list[] = $row;
  100. $i++;
  101. }
  102. $pr_encode = array();
  103. foreach ($_REQUEST as $key => $val) {
  104. if (!in_array($key, array('product', 'pid'))) {
  105. continue;
  106. }
  107. $val = preg_replace("#[^0-9a-z]#i", "", $val);
  108. $pr_encode[$key] = $val;
  109. }
  110. $pr_encode = str_replace('=', '', mchStrCode(json_encode($pr_encode)));
  111. $pr_verify = md5("payment".$pr_encode.$cfg_cookie_encode);
  112. $tpl = new DedeTemplate();
  113. $tpl->LoadTemplate(DEDEMEMBER.'/templets/buy_action_payment.htm');
  114. $tpl->Display();
  115. } else {
  116. $moRow = $dsql->GetOne("SELECT * FROM `#@__member_operation` WHERE buyid='$buyid'");
  117. if ($moRow['sta'] == 2) {
  118. ShowMsg("已完成支付,无需重复付款", "javascript:;");
  119. exit;
  120. }
  121. if($paytype === 1) {
  122. //微信支付
  123. include_once(DEDEINC.'/sdks/include.php');
  124. include_once(DEDEINC.'/libraries/oxwindow.class.php');
  125. $pInfo = $dsql->GetOne("SELECT * FROM `#@__sys_payment` WHERE id = $paytype");
  126. $pData = (array)json_decode($pInfo['config']);
  127. $config = array(
  128. "appid" => $pData['AppID'],
  129. "mch_id" => $pData['MchID'],
  130. "mch_key" => $pData['APIv2Secret'],
  131. );
  132. $wechat = new \WeChat\Pay($config);
  133. $options = array(
  134. 'product_id' => $buyid,
  135. 'body' => '测试商品',
  136. 'out_trade_no' => $buyid,
  137. 'total_fee' => $row['money']*100,
  138. 'trade_type' => 'NATIVE',
  139. 'notify_url' => 'https://www.dedebiz.com/notify?platform=wxpay',
  140. );
  141. try {
  142. // 生成预支付码
  143. $result = $wechat->createOrder($options);
  144. $payurl = $result['code_url'];
  145. $msg = "请使用微信扫一扫,扫描二维码支付:<div id='qrcode' style='width:200px; height:200px; margin-top:15px;'></div><br/><a href='buy_action.php?dopost=wechat_ok&buyid={$buyid}' class='btn btn-success btn-sm'>已完成支付</a> <a href='operation.php' class='btn btn-outline-success btn-sm'>返回订单管理</a>";
  146. $script = '<script type="text/javascript">var qrcode = new QRCode(document.getElementById("qrcode"), {
  147. width : 300,
  148. height : 300,
  149. correctLevel : 3
  150. });qrcode.makeCode("'.$payurl.'");</script>';
  151. $wintitle = "微信支付";
  152. $wecome_info = " ";//这个空格不要去
  153. $win = new OxWindow();
  154. $win->AddMsgItem($msg);
  155. $winform = $win->GetWindow("hand", "&nbsp;", false);
  156. $win->Display(DEDEMEMBER."/templets/win_templet.htm");
  157. } catch (Exception $e) {
  158. ShowMsg("生成微信支付信息失败,请联系网站管理员", "javascript:;");
  159. exit;
  160. }
  161. } elseif ($paytype === 2) {
  162. include_once(DEDEINC.'/libraries/oxwindow.class.php');
  163. $pInfo = $dsql->GetOne("SELECT * FROM `#@__sys_payment` WHERE id = $paytype");
  164. $pData = (array)json_decode($pInfo['config']);
  165. $config = array(
  166. "sign_type" => $pData['SignType'],
  167. "appid" => $pData['APPID'],
  168. "private_key" => $pData['PrivateKey'],
  169. "public_key" => $pData['CertPublicKey'],
  170. "notify_url" => 'https://www.dedebiz.com/alipay-notify.php',
  171. "return_url" => 'https://www.dedebiz.com/alipay-notify.php',
  172. );
  173. //支付宝
  174. try {
  175. // 实例支付对象
  176. $pay = \AliPay\Web::instance($config);
  177. // 参考链接:https://docs.open.alipay.com/api_1/alipay.trade.page.pay
  178. $result = $pay->apply(array([
  179. 'out_trade_no' => $buyid, // 商户订单号
  180. 'total_amount' => sprintf("%d",$row['money']), // 支付金额
  181. 'subject' => '支付订单描述', // 支付订单描述
  182. ]));
  183. var_dump(htmlspecialchars( $result));
  184. } catch (Exception $e) {
  185. echo $e->getMessage();
  186. }
  187. } elseif ($paytype === 3) {
  188. include_once(DEDEINC.'/libraries/oxwindow.class.php');
  189. //银行转账
  190. $pInfo = $dsql->GetOne("SELECT * FROM `#@__sys_payment` WHERE id = $paytype");
  191. $pData = (array)json_decode($pInfo['config']);
  192. $msg = "请汇款至如下账户:<br><b>账户名:</b>{$pData['AccountName']}<br><b>账号:</b>{$pData['AccountNO']}<br><b>开户行:</b>{$pData['Name']}<br/><b>备注:</b>{$buyid}<br/>如您已经完成转账,请点击下面按钮,等待管理员确认后即可完成充值<br><br><a href='buy_action.php?dopost=bank_ok&buyid={$buyid}' class='btn btn-success btn-sm'>已完成银行转账</a> <a href='operation.php' class='btn btn-outline-success btn-sm'>返回订单管理</a>";
  193. $wintitle = "银行转账";
  194. $wecome_info = " ";//这个空格不要去
  195. $win = new OxWindow();
  196. $win->AddMsgItem($msg);
  197. $winform = $win->GetWindow("hand", "&nbsp;", false);
  198. $win->Display(DEDEMEMBER."/templets/win_templet.htm");
  199. } elseif ($paytype === 4) {
  200. //余额付款
  201. if ($cfg_ml->M_UserMoney < $row['money']) {
  202. ShowMsg("余额不足,请确保当前账户有足够金币支付", "javascript:;");
  203. exit;
  204. }
  205. $query = "UPDATE `#@__member_operation` SET sta = '2' WHERE buyid = '$buyid'";
  206. $dsql->ExecuteNoneQuery($query);
  207. $query = "UPDATE `#@__member` SET money = money+{$row['num']} WHERE mid = '$mid'";
  208. $dsql->ExecuteNoneQuery($query);
  209. $query = "UPDATE `#@__member` SET user_money = user_money-{$row['money']} WHERE mid = '$mid'";
  210. $dsql->ExecuteNoneQuery($query);
  211. ShowMsg("成功使用余额付款", "javascript:;");
  212. exit;
  213. } elseif ($paytype === 5) {
  214. //货到付款
  215. ShowMsg("虚拟物品,不支持货到付款", "javascript:;");
  216. exit;
  217. }
  218. }
  219. /**
  220. * 加密函数
  221. *
  222. * @access public
  223. * @param string $string 字符串
  224. * @param string $operation 操作
  225. * @return string
  226. */
  227. function mchStrCode($string, $operation = 'ENCODE')
  228. {
  229. $key_length = 4;
  230. $expiry = 0;
  231. $key = md5($GLOBALS['cfg_cookie_encode']);
  232. $fixedkey = md5($key);
  233. $egiskeys = md5(substr($fixedkey, 16, 16));
  234. $runtokey = $key_length ? ($operation == 'ENCODE' ? substr(md5(microtime(true)), -$key_length) : substr($string, 0, $key_length)) : '';
  235. $keys = md5(substr($runtokey, 0, 16).substr($fixedkey, 0, 16).substr($runtokey, 16).substr($fixedkey, 16));
  236. $string = $operation == 'ENCODE' ? sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$egiskeys), 0, 16).$string : base64_decode(substr($string, $key_length));
  237. $i = 0;
  238. $result = '';
  239. $string_length = strlen($string);
  240. for ($i = 0; $i < $string_length; $i++) {
  241. $result .= chr(ord($string[$i]) ^ ord($keys[$i % 32]));
  242. }
  243. if ($operation == 'ENCODE') {
  244. return $runtokey.str_replace('=', '', base64_encode($result));
  245. } else {
  246. if ((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$egiskeys), 0, 16)) {
  247. return substr($result, 26);
  248. } else {
  249. return '';
  250. }
  251. }
  252. }