<?php
namespace Biz\Payment;
/**
 * 金付卡支付
 */
class GoldCardPayment extends \Biz\BasePayment {

	protected $gatWay = "http://www.goldenpay88.com/gateway/orderPay";
	protected $paymentName = "GoldCard";
	public function toPay($order) {
		$data = array();
		$data['terId'] = ''; //商户号
		$data['businessOrdid'] = $this->dataAccess->orderSn; //订单号
		$data['orderName'] = $this->dataAccess->goodsName;
		$data['tradeMoney'] = $this->dataAccess->money * 100;
		$data['selfParam'] = '';
		$data['payType'] = empty($this->dataAccess->payType) ? '1000' : $this->dataAccess->payType;
		$data['appSence'] = $this->dataAccess->paySet;
		$data['syncURL'] = $this->redirectUrl;
		$data['asynURL'] = $this->notifyUrl;

		$enc_json = json_encode($data, JSON_UNESCAPED_UNICODE);
		$Split = str_split($enc_json, 64);
		ForEach ($Split as $Part) {
			openssl_public_encrypt($Part, $PartialData, $pubkey); //服务器公钥加密
			$t = strlen($PartialData);
			$encParam_encrypted .= $PartialData;
		}

		$encParam = base64_encode(($encParam_encrypted)); //加密的业务参数
		openssl_sign($encParam_encrypted, $sign_info, $priKey);
		$sign = base64_encode($sign_info); //加密业务参数的签名

		$data = array();
		$data['merId'] = ''; //终端号
		$data['version'] = '1.0.9';
		$data['sign'] = $sign;
		$data['encParam'] = $encParam;

		$this->goPay($data);

	}

	public function redirect($order) {

	}

	public function notify($order) {
		$re = $this->check($order);
		if ($re) {
			return 'success';
		}
		return 'fail';
	}

	function check($order) {
		$data = array();

		if ($data['signature'] == $md5sign) {
			return 1;
		}
		return 0;
	}

	function rsaDecode($data) {

	}
	/**
	 * 得到所有设备
	 * @return [type] [description]
	 */
	function getSetname() {
		return array(
			'pc' => '1001', //
			'h5' => '1002', //
			'kuaijieApi' => '1003', //
			'kuaijiesdk' => '1004', //
		);
	}
	public function getPaymentType() {
		# code...
		return array(
			'all' => '1000', //默认支持所有
			'kuaijie' => '1001',
			'shuakaqi' => '1002', //刷卡器支付
			'kuaijie' => '1003', //银行卡支付
			'scan_weixin_qr' => '1005', //微信扫码支付
			'scan_alipay_qr' => '1006', //支付宝扫码支付
			'foreign_card' => '1007', //外卡支付
			'alipay_app' => '1008', //支付宝 APP 支付
			'weixin_app' => '1009', //微信 APP 支付
		);
	}
}

?>


