dever 2 years ago
parent
commit
065809d227
5 changed files with 108 additions and 54 deletions
  1. 1 1
      lib/Alipay.php
  2. 1 1
      lib/Cmbc.php
  3. 1 1
      lib/Wechat.php
  4. 104 50
      lib/Yspay.php
  5. 1 1
      src/Api.php

+ 1 - 1
lib/Alipay.php

@@ -62,7 +62,7 @@ class Alipay extends Core
 	/**
 	 * 获取统一下单的基本信息
 	 */
-	public function order($account_id, $project_id, $uid, $username, $product_id, $name, $cash, $openid = false, $type = 1, $order_id = false, $other = false)
+	public function order($account_id, $project_id, $uid, $username, $product_id, $name, $cash, $openid = false, $type = 1, $order_id = false, $other = false, $refer = false)
 	{
 		$order_id = $this->createOrder($uid, $username, $account_id, $project_id, $product_id, $name, $cash, $this->config['type'], $order_id);
 

+ 1 - 1
lib/Cmbc.php

@@ -48,7 +48,7 @@ class Cmbc extends Core
 	/**
 	 * 获取统一下单的基本信息
 	 */
-	public function order($account_id, $project_id, $uid, $username, $product_id, $name, $cash, $openid = false, $type = 1, $order_id = false)
+	public function order($account_id, $project_id, $uid, $username, $product_id, $name, $cash, $openid = false, $type = 1, $order_id = false, $other = false, $refer = false)
 	{
 		$trade_type = $this->getType($type);
 		$order_id = $this->createOrder($uid, $username, $account_id, $project_id, $product_id, $name, $cash, $this->config->GetType(), $order_id);

+ 1 - 1
lib/Wechat.php

@@ -75,7 +75,7 @@ class Wechat extends Core
 	/**
 	 * 获取统一下单的基本信息
 	 */
-	public function order($account_id, $project_id, $uid, $username, $product_id, $name, $cash, $openid = false, $type = 1, $order_id = false, $other = false)
+	public function order($account_id, $project_id, $uid, $username, $product_id, $name, $cash, $openid = false, $type = 1, $order_id = false, $other = false, $refer = false)
 	{
 		$trade_type = $this->getType($type);
 		$order_id = $this->createOrder($uid, $username, $account_id, $project_id, $product_id, $name, $cash, $this->config->GetType(), $order_id);

+ 104 - 50
lib/Yspay.php

@@ -109,11 +109,36 @@ class Yspay extends Core
 		}
 	}
 
+	private function getType($type)
+	{
+		switch ($type) {
+			case 1:
+				//小程序支付
+				$type = 'MINI';
+				break;
+			
+			case 2://扫码支付
+				$type = 'APP';
+				break;
+
+			case 3://APP支付
+				$type = 'APP';
+				break;
+
+			case 4://页面拉起支付
+				$type = 'YUEDAN';
+				break;
+		}
+
+		return $type;
+	}
+
 	/**
 	 * 获取统一下单的基本信息
 	 */
-	public function order($account_id, $project_id, $uid, $username, $product_id, $name, $cash, $openid = false, $type = 1, $order_id = false, $other = false)
+	public function order($account_id, $project_id, $uid, $username, $product_id, $name, $cash, $openid = false, $type = 1, $order_id = false, $other = false, $refer = false)
 	{
+		$trade_type = $this->getType($type);
 		$order_id = $this->createOrder($uid, $username, $account_id, $project_id, $product_id, $name, $cash, $this->config['type'], $order_id);
 
 		if (isset($this->config['prefix']) && $this->config['prefix']) {
@@ -125,14 +150,14 @@ class Yspay extends Core
 
 		$request['mid'] = $this->config['mid'];
 		$request['tid'] = $this->config['tid'];
-		$request['instMid'] = 'MINIDEFAULT';
+		$request['instMid'] = $trade_type . 'DEFAULT';
 		$request['totalAmount'] = round($cash * 100, 2);
 		//$request['totalAmount'] = 100;
 		$request['subAppId'] = $this->config['sub_appid'];
 		$request['requestTimestamp'] = date("Y-m-d H:i:s");
 		$request['expireTime'] = date("Y-m-d H:i:s", time() + $this->config['timeout']); 
 		$request['notifyUrl'] = $this->config['notify'];
-		$request['tradeType'] = 'MINI';
+		$request['tradeType'] = $trade_type;
 
 		if ($other) {
 			$request['originalAmount'] = round($other['oprice'] * 100, 2);
@@ -175,7 +200,7 @@ class Yspay extends Core
 				$this->updateOrderParam($order_id, $result);
 				return $result['payMsg'];
 			}
-		} else {
+		} elseif ($type == 1) {
 			# 小程序支付
 			$result = Base::pay($request, $this->config);
 
@@ -189,6 +214,14 @@ class Yspay extends Core
 				$this->updateOrderParam($order_id, $result);
 				return $result['payMsg'];
 			}
+		} elseif ($type == 4) {
+			if ($refer) {
+				$request['returnUrl'] = $refer;
+			}
+
+			$result = Base::h5_pay($request, $this->config);
+
+			return $result;
 		}
 		return false;
 	}
@@ -319,49 +352,11 @@ class Yspay extends Core
 
 
 	/**
-	 * 获取页面支付
+	 * 获取页面支付 去收银台
 	 */
 	public function page($order, $refer)
 	{
-		$refer = urldecode($refer);
-		$tools = new \JsApiPay($this->config);
-		$info = $tools->GetJsApiParameters($order);
-
-		$html = '<script type="text/javascript">
-		function jsApiCall()
-		{
-			WeixinJSBridge.invoke(
-				"getBrandWCPayRequest",
-				'.$info.',
-				function(res){
-					//WeixinJSBridge.log(res.err_msg);
-					if(res.err_msg == "get_brand_wcpay_request:ok")
-					{
-						location.href = "'.$refer.'";
-					} else {
-						alert(res.err_code+res.err_desc+res.err_msg);
-					}
-				}
-			);
-		}
-
-		function callpay()
-		{
-			if (typeof WeixinJSBridge == "undefined"){
-			    if( document.addEventListener ){
-			        document.addEventListener("WeixinJSBridgeReady", jsApiCall, false);
-			    }else if (document.attachEvent){
-			        document.attachEvent("WeixinJSBridgeReady", jsApiCall); 
-			        document.attachEvent("onWeixinJSBridgeReady", jsApiCall);
-			    }
-			}else{
-			    jsApiCall();
-			}
-		}
-		callpay();
-		</script>';
-
-		return $html;
+		return $order;
 	}
 }
 
@@ -401,6 +396,12 @@ class Base
 	# 二维码支付退款
 	static $qrcode_refund_url = 'v1/netpay/bills/refund';
 
+	# h5支付
+	static $h5_url = 'v1/netpay/webpay/pay';
+
+	# h5支付退款
+	static $h5_refund_url = 'v1/netpay/wx/app-pre-order';
+
 
 	//===================== 支付相关 ==============================
 	/**
@@ -414,6 +415,17 @@ class Base
 		return $result;
 	}
 
+	/**
+	 * h5支付
+	 */
+	static public function h5_pay($param, $config)
+	{
+		$url = self::$h5_url;
+		$result = self::get($url, $param, $config);
+
+		return $result;
+	}
+
 	/**
 	 * 获取支付二维码
 	 */
@@ -492,6 +504,8 @@ class Base
 	{
 		if ($type === 'token') {
 			return self::getAccessTokenByToken($config);
+		} elseif ($type === 'form') {
+			return self::getAccessTokenByForm($param, $config);
 		}
 		return self::getAccessTokenBySig($param, $config);
 	}
@@ -530,6 +544,26 @@ class Base
 		return 'OPEN-BODY-SIG AppId="'.$param['AppId'].'", Timestamp="'.$param['Timestamp'].'", Nonce="'.$param['Nonce'].'", Signature="'.self::signature2($data, $param, $config['appsecret']).'"';
 	}
 
+	/**
+	 * 方式三,OPEN-FORM-PARAM方式
+	 */
+	static function getAccessTokenByForm($data, $config)
+	{
+		$content = Dever::json_encode($data);
+		$param = [
+			'appId' => $config['appid'],
+			'timestamp' => date('YmdHis'),
+			'nonce' => md5(uniqid(microtime(true),true)),
+			'authorization' => 'OPEN-FORM-PARAM',
+			'content' => $content,
+		];
+		$param['signature'] = urlencode(self::signature3($param, $config['appsecret']));
+
+		$param['content'] = urlencode($param['content']);
+
+		return $param;
+	}
+
 	/**
 	 * 计算签名,方式一
 	 */
@@ -547,16 +581,36 @@ class Base
 		return base64_encode(hash_hmac('sha256', $param['AppId'].$param['Timestamp'].$param['Nonce'].$str, $appsecret, true));
 	}
 
+	/**
+	 * 计算签名,方式三
+	 */
+	static function signature3($param, $appsecret)
+	{	
+		$str = bin2hex(hash('sha256', $param['content'], true));
+		return base64_encode(hash_hmac('sha256', $param['appId'].$param['timestamp'].$param['nonce'].$str, $appsecret, true));
+	}
+
 	/**
 	 * 获取信息
 	 */
     static function get($url, $param, $config, $state = true)
     {
     	$url = $config['box'] == 1 ? self::$host . $url : self::$test_host . $url;
-    	
-    	$header = array();
-    	$header['Authorization'] = self::getAuth('sig', $param, $config);
-		$result = Dever::curl($url, $param, 'post', true, $header);
+
+    	if (strstr($url, 'webpay')) {
+    		$url .= '?';
+    		$param = self::getAuth('form', $param, $config);
+    		foreach ($param as $k => $v) {
+    			$url .= '&' . $k . '=' . $v;
+    		}
+    		$url = str_replace('?&', '?', $url);
+    		return $url;
+    	} else {
+    		$header = array();
+    		$header['Authorization'] = self::getAuth('sig', $param, $config);
+			$result = Dever::curl($url, $param, 'post', true, $header);
+    	}
+
 		if (strstr($result, '<html><head>')) {
 			Dever::alert('系统错误');
 		}
@@ -568,10 +622,10 @@ class Base
 			if ($result['errCode'] == '0000' || $result['errCode'] == 'SUCCESS') {
 				return $result;
 			} elseif (isset($result['errInfo'])) {
-				Dever::alert('操作失败,请联系管理员');
+				//Dever::alert('操作失败,请联系管理员');
 				Dever::alert($result['errInfo']);
 			} elseif (isset($result['errMsg'])) {
-				Dever::alert('操作失败,请联系管理员');
+				//Dever::alert('操作失败,请联系管理员');
 				Dever::alert($result['errMsg']);
 			}
 		} else {

+ 1 - 1
src/Api.php

@@ -44,7 +44,7 @@ class Api
 				return $order;
 			}
 		}
-		return $this->method->order($this->account_id, $this->project_id, $this->uid, $this->username, $this->product_id, $this->name, $this->cash, $this->openid, $type, $this->order_id, $this->other);
+		return $this->method->order($this->account_id, $this->project_id, $this->uid, $this->username, $this->product_id, $this->name, $this->cash, $this->openid, $type, $this->order_id, $this->other, $this->refer);
 	}
 
 	/**