Exemplo n.º 1
0
	private function code($orderid, $price)
	{
		import('@.ORG.Weixinnewpay.WxPayPubHelper');
		$jsApi = new JsApi_pub($this->payConfig['new_appid'], $this->payConfig['mchid'], $this->payConfig['key'], $this->payConfig['appsecret']);
		$unifiedOrder = new UnifiedOrder_pub($this->payConfig['new_appid'], $this->payConfig['mchid'], $this->payConfig['key'], $this->payConfig['appsecret']);
		$unifiedOrder->setParameter('body', $orderid);

		if ($this->_issystem == 1) {
			$out_trade_no = $orderid . '_system';
		}
		else if ($this->_issystem == 2) {
			$out_trade_no = $orderid . '_other';
		}

		$unifiedOrder->setParameter('out_trade_no', $out_trade_no);
		$unifiedOrder->setParameter('total_fee', $price * 100);

		if (strpos(CONF_PATH, 'DataPig')) {
			$noticeFileName = 'notice_datapig.php';
		}
		else if (strpos(CONF_PATH, 'PigData')) {
			$noticeFileName = 'notice_pigdata.php';
		}
		else {
			$noticeFileName = 'notice.php';
		}

		$unifiedOrder->setParameter('notify_url', $this->siteUrl . '/wxpay/' . $noticeFileName);
		$unifiedOrder->setParameter('trade_type', 'NATIVE');
		$unifiedOrder->setParameter('attach', 'token=' . $_GET['token'] . '&wecha_id=' . $_GET['wecha_id'] . '&from=' . $_GET['from'] . '&pl=' . $this->_issystem);
		$prepay_result = $unifiedOrder->getPrepayResult();

		if ($prepay_result['return_code'] == 'FAIL') {
			return array('error' => 1, 'msg' => '没有获取微信支付的预支付ID,请重新发起支付!<br/><br/>微信支付错误返回:' . $prepay_result['return_msg']);
		}

		if ($prepay_result['err_code']) {
			return array('error' => 1, 'msg' => '没有获取微信支付的预支付ID,请重新发起支付!<br/><br/>微信支付错误返回:' . $prepay_result['err_code_des']);
		}

		$jsApi->setPrepayId($prepay_result['prepay_id']);
		return $prepay_result['code_url'];
	}