<?php
namespace Biz\Pay\Payment;
/**
 * 汇付天下接口
 */
class RenXinPayment extends \Biz\Pay\BasePayment {
	function init() {
		$this->sellerInfo = array(
			'busKey' => "fbce600379c88a223c70d6a566d834bf",
			'busAccount' => '20424',
		);
		# code...
	}
	protected $getWay = "http://dpos.qqjun.cn/Online/GateWay";
	protected $paymentName = "RenXin";
	function toPay() {
	    dd($this->getConfig());
		$data = array(
			'version' => '3.0',
			'method' => 'Rx.online.pay',
			'partner' => $this->sellerInfo['busAccount'],
			'banktype' => '',
			'paymoney' => $this->dataAccess->money,
			'ordernumber' => $this->dataAccess->orderSn,
			'callbackurl' => $this->notifyUrl,
		);
		$sign = $this->md5mcrypt($data, $this->sellerInfo['busKey']);
		$data['hrefbackurl'] = $this->redirectUrl;
		$data['sign'] = $sign;
		$this->goPay($data);
	}
	function md5mcrypt($data, $key) {
		$str = http_build_query($data) . $key;
		$str = urldecode($str);
		return md5($str);
	}

	public function notify($order) {
		# code...
		$re = $this->check($order);
		return $re;
	}
	public function redirect($order) {
		$re = $this->check($order);
		return $re;
	}

	public function check($order) {
		$data = array();
		$data['partner'] = $_GET['partner'];
		$this->dataAccess->orderSn = $data['ordernumber'] = $_GET['ordernumber'];
		$data['orderstatus'] = $_GET['orderstatus'];
		$this->dataAccess->money = $data['paymoney'] = $_GET['paymoney'];

		$sign = $this->md5mcrypt($data, $this->sellerInfo['busKey']);
		$this->dataAccess->goodsName = '';
		$data['sysnumber'] = $_GET['sysnumber'];
		$data['attach'] = $_GET['attach'];
		$data['sign'] = $_GET['sign'];
		if ($sign == $data['sign']) {
			if ($data['orderstatus'] == '1') {
				return 1;
			} else {
				return 0;
			}
		}

	}

	function notifyMsg($key) {
		if ($key > 0) {
			echo 'ok';
		} else {
			echo '';
		}
	}
	public function getPaymentType() {
		# code...
		return array(
			"alipay" => "ALIPAY", //"支付宝",
			"weixin" => "WEIXIN", //"微信",
			"qqpay" => "QQ ", //QQ钱包",
			'tenpay' => 'TENPAY', //财付通
		);
	}
}