1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
| <?php namespace Home\Controller;
use Think\Controller; use Common\Controller\HomeController; class PayController extends HomeController {
function __construct() { parent::__construct(); $testConfig = array( 'payUrl' => 'https://www.sandbox.paypal.com/cgi-bin/webscr', 'business' => '3HSV6******', 'currency_code' => 'USD', 'lc' => 'US', 'key' => 'webape', ); $prodConfig = array( 'payUrl' => 'https://www.paypal.com/cgi-bin/webscr', 'business' => '3HSV6******', 'currency_code' => 'USD', 'lc' => 'US', 'key' => 'webape', ); $payConfig = $testConfig; $this->payConfig = $payConfig; }
public function paypalpay() { $oid = I('oid'); $order = M('order')->find($oid); if (!$order) { $this->display('Public:404'); exit(); } $data = $this->payConfig; $orderDetail = M('order_detail')->where(array('oid' => $oid))->select(); $goodsInfo = ''; foreach ($orderDetail as $k => $v) { $product = M($v['name'])->field('title')->find($v['pid']); $product_color = M($v['name'] . '_colors')->field('title')->find($v['color_id']); $goodsInfo .= $product['title'] . '-' . $product_color['title'] . '-' . $v['diameter'] . '-' . $v['number'] . '-'; } $signSrc = ''; $signArr = array( 'invoice' => $order['order_num'], 'key' => $data['key'], ); foreach ($signArr as $k => $v) { $signSrc .= $v; } $signInfo = strtoupper(hash("sha256", $signSrc)); $formData = array( 'cmd' => '_xclick', 'business' => $data['business'], 'item_name' => string_replace($goodsInfo), 'currency_code' => $data['currency_code'], 'amount' => $order['real_money'], 'notify_url' => C('PROTOCOL') . $_SERVER['SERVER_NAME'] . U('Pay/paypalnotifyurl'), 'return' => C('PROTOCOL') . $_SERVER['SERVER_NAME'] . U('Order/info', array('order_num' => $order['order_num'], 'paypal' => 1)), 'cancel_return' => C('PROTOCOL') . $_SERVER['SERVER_NAME'] . U('Order/info', array('order_num' => $order['order_num'])), 'invoice' => $order['order_num'], 'no_shipping' => 1, 'custom' => $signInfo, 'charset' => 'utf8', 'lc' => $data['lc'], ); header("Content-type: text/html; charset=utf-8"); $payForm = '<form action="' . $data['payUrl'] . '" method="post" id="form" name="form">' . inputs($formData) . '</form><script>document.form.submit()</script>'; echo $payForm; }
public function paypalnotifyurl() { $data = $this->payConfig; $getData = array( 'invoice' => I('post.invoice'), 'key' => $data['key'], ); $payment_status = I('post.payment_status'); $custom = I('post.custom'); $signSrc = ''; foreach ($getData as $k => $v) { $signSrc .= $v; } $signInfo = strtoupper(hash("sha256", $signSrc)); if ($signInfo == $custom && $payment_status == 'Completed') { $saveData = array( 'pay_create_time' => time(), 'pay_sign_info' => $signInfo, 'status' => 2, ); $re = M('order')->where(array('order_num' => $getData['invoice']))->data($saveData)->save(); $payResult = "Congratulations,payment is successful !"; } else { $payResult = "Data validation failed"; }
$logData = I('post.'); $logfile = __ROOT__ . '/payPalLog_c451f8e6e53014.txt'; import("Org.Util.File"); $logObj = new \File($logfile); $logfile = $logObj->getRealFile(); file_put_contents($logfile, serialize($logData), FILE_APPEND); } } 上面有用到一个input组装函数:
function inputs($data){ $inputs=''; foreach($data as $k=>$v){ $inputs.='<input type="hidden" name="'.$k.'" value="'.$v.'"/>'; } return $inputs; }
|