<?php
namespace Biz\Pay\Payment;
/**
 * 汇付天下接口
 */
class DuoBaoPayment extends \Biz\Pay\BasePayment {
	function init() {
		$this->sellerInfo = array(
			'busKey' => "9e4503ba878d4019b62127fa0b27c65c",
			'busAccount' => '987858', //360cd.cn
		);
		# code...
	}
	protected $getWay = "https://gw.169.cc/interface/AutoBank/CashierDesk.aspx";
	protected $paymentName = "DuoBao";
	function toPay() {
		$data = array(
			'parter' => $this->sellerInfo['busAccount'],
			'type' => 0,
			'value' => $this->dataAccess->money,
			'orderid' => $this->dataAccess->orderSn,
			'callbackurl' => $this->notifyUrl,
		);
		$sign = $this->md5mcrypt($data, $this->sellerInfo['busKey']);
		$data['onlyqr'] = '';
		$data['attach'] = '';
		$data['hrefbackurl'] = $this->redirectUrl;
		$data['sign'] = $sign;
		$data = $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();
		$this->dataAccess->orderSn = $data['orderid'] = $_GET['orderid'];
		$data['opstate'] = $_GET['opstate'];
		$this->dataAccess->money = $data['ovalue'] = $_GET['ovalue'];
		$sign = $this->md5mcrypt($data, $this->sellerInfo['busKey']);
		$this->dataAccess->goodsName = '';
		$data['sysorderid'] = $_GET['sysorderid'];
		$data['attach'] = $_GET['attach'];
		$data['msg'] = $_GET['msg'];
		$data['sign'] = $_GET['sign'];
		if ($sign == $data['sign']) {
			if ($data['opstate'] == '0') {
				return 1;
			} else {
				return 0;
			}
		}

	}

	function notifyMsg($key) {
		if ($key > 0) {
			echo 'opstate=0';
		} else {
			echo '';
		}
	}
	public function getPaymentType() {
		# code...
		return array(
			"alipay" => "1006", //"支付宝",
			"weixin" => "1007", //"微信",
			"qqpay" => "993 ", //QQ钱包",
		);
	}

}