dever 6 years ago
parent
commit
b2cfd3067d
2 changed files with 45 additions and 2 deletions
  1. 33 2
      lib/Wechat.php
  2. 12 0
      src/Api.php

+ 33 - 2
lib/Wechat.php

@@ -38,7 +38,10 @@ class Wechat extends Core
 		$trade_type = $this->getType($type);
 		$order_id = $this->createOrder($uid, $username, $account_id, $project_id, $product_id, $name, $cash, $this->config->GetType(), $order_id);
 		$tools = new \JsApiPay($this->config);
-		$openid = $openid ? $openid : $tools->GetOpenid();
+
+		if ($openid != -1) {
+			$openid = $openid ? $openid : $tools->GetOpenid();
+		}
 		$input = new \WxPayUnifiedOrder();
 		$input->SetBody($name);
 		$input->SetAttach($name);
@@ -50,7 +53,10 @@ class Wechat extends Core
 		$input->SetNotify_url($this->config->GetNotifyUrl());
 		$input->SetTrade_type($trade_type);
 		$input->SetProduct_id($product_id);
-		$input->SetOpenid($openid);
+		if ($openid != -1) {
+			$input->SetOpenid($openid);
+		}
+		
 		if ($type == 1) {
 			$order = \WxPayApi::unifiedOrder($this->config, $input);
 			# 下单信息
@@ -97,6 +103,27 @@ class Wechat extends Core
 		return $order;
 	}
 
+	/**
+	 * 获取app支付
+	 */
+	public function app($order)
+	{
+		if (isset($order['prepay_id'])) {
+			$order['partnerid'] = $this->config->GetMerchantId();
+			$order['package'] = 'Sign=WXPay';
+
+			$string = 'appid='.$this->config->GetAppId().'&partnerid='.$order['partnerid'].'&prepayid='.$order['prepay_id'].'&package='.$order['package'].'&noncestr='.$order['nonce_str'].'&timestamp='.$order['time'];
+			if($order['sign_type'] == "MD5"){
+				$string = md5($string);
+			} else {
+				$string = hash_hmac("sha256", $string, $this->config->GetKey());
+			}
+
+			$order['sign'] = $string;
+		}
+		return $order;
+	}
+
 
 	/**
 	 * 获取页面支付
@@ -154,6 +181,10 @@ class Wechat extends Core
 			case 2:
 				$type = 'NATIVE';
 				break;
+
+			case 3:
+				$type = 'APP';
+				break;
 		}
 
 		return $type;

+ 12 - 0
src/Api.php

@@ -51,6 +51,18 @@ class Api
 		return $this->method->applet($this->get(1));
 	}
 
+	/**
+	 * 发起支付 用于app支付
+	 *
+	 * @return mixed
+	 */
+	public function app($param = array())
+	{
+		$this->init($param);
+		$this->openid = -1;
+		return $this->method->app($this->get(3));
+	}
+
 	/**
 	 * 发起支付 用于页面支付
 	 *