$PAY = cache_read('pay.php'); if (!$PAY[$bank]['enable']) { wx_exit(); } if (strlen($PAY[$bank]['keycode']) < 7) { wx_exit(); } if (strpos($xml, 'result_code') !== false) { $x = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); $x = (array) $x; $post = array(); foreach ($x as $k => $v) { $post[$k] = $v; } unset($post['sign']); if ($post['result_code'] == 'SUCCESS' && make_sign($post, $PAY[$bank]['keycode']) == $x['sign']) { $itemid = intval($post['out_trade_no']); $total_fee = $post['total_fee'] / 100; $r = $db->get_one("SELECT * FROM {$DT_PRE}finance_charge WHERE itemid='{$itemid}'"); if ($r) { if ($r['status'] == 3) { wx_exit('ok'); } if ($r['status'] == 0) { $charge_orderid = $r['itemid']; $charge_money = $r['amount'] + $r['fee']; $charge_amount = $r['amount']; $editor = 'N' . $bank; if ($total_fee == $charge_money) { $db->query("UPDATE {$DT_PRE}finance_charge SET status=3,money={$charge_money},receivetime='{$DT_TIME}',editor='{$editor}' WHERE itemid={$charge_orderid}"); require DT_ROOT . '/include/module.func.php';
return $str; } $charge = $r['amount'] + $r['fee']; $post = array(); $post['appid'] = $PAY[$bank]['appid']; $post['mch_id'] = $PAY[$bank]['partnerid']; $post['nonce_str'] = random(32); $post['body'] = $charge_title ? $charge_title : '会员(' . $_username . ')充值(流水号:' . $orderid . ')'; $post['body'] = convert($post['body'], DT_CHARSET, 'UTF-8'); $post['out_trade_no'] = $itemid; $post['total_fee'] = $charge * 100; $post['spbill_create_ip'] = $DT_IP; $post['notify_url'] = DT_PATH . 'api/pay/' . $bank . '/' . ($PAY[$bank]['notify'] ? $PAY[$bank]['notify'] : 'notify.php'); $post['trade_type'] = 'NATIVE'; $post['product_id'] = $itemid; $post['sign'] = make_sign($post, $PAY[$bank]['keycode']); $rec = dcurl('https://api.mch.weixin.qq.com/pay/unifiedorder', make_xml($post)); #log_write($rec, 'wxr', 1); if (strpos($rec, 'code_url') !== false) { $x = simplexml_load_string($rec, 'SimpleXMLElement', LIBXML_NOCDATA); } else { if (strpos($rec, 'return_msg') !== false) { $x = simplexml_load_string($rec, 'SimpleXMLElement', LIBXML_NOCDATA); dalert(convert($x->return_msg, 'UTF-8', DT_CHARSET), $MODULE[2]['linkurl'] . 'charge.php?action=record'); } else { dalert('Can Not Connect weixin', $MODULE[2]['linkurl'] . 'charge.php?action=record'); } } ?> <html> <head>