dever 6 years ago
parent
commit
d1761cbcdc
2 changed files with 37 additions and 2 deletions
  1. 19 0
      lib/Wechat.php
  2. 18 2
      src/Api.php

+ 19 - 0
lib/Wechat.php

@@ -77,6 +77,25 @@ class Wechat extends Core
 		return $url;
 	}
 
+	/**
+	 * 获取小程序支付
+	 */
+	public function applet($order)
+	{
+		if (isset($order['prepay_id'])) {
+
+			$string = 'appId='.$this->config->GetAppId().'&nonceStr='.$order['nonce_str'].'&package=prepay_id='.$order['prepay_id'].'&signType='.$order['sign_type'].'&timeStamp='.$order['time'].'&key='.$this->config->GetKey();
+			if($order['sign_type'] == "MD5"){
+				$string = md5($string);
+			} else {
+				$string = hash_hmac("sha256", $string, $this->config->GetKey());
+			}
+
+			$order['sign'] = $string;
+		}
+		return $order;
+	}
+
 
 	/**
 	 * 获取页面支付

+ 18 - 2
src/Api.php

@@ -26,14 +26,26 @@ class Api
 	}
 
 	/**
-	 * 发起支付 用于页面支付(jsapi、小程序、支付宝h5等)
+	 * 发起支付 用于小程序支付
+	 *
+	 * @return mixed
+	 */
+	public function applet($param = array())
+	{
+		$this->init($param);
+		return $this->method->applet($this->get(1));
+	}
+
+	/**
+	 * 发起支付 用于页面支付
 	 *
 	 * @return mixed
 	 */
 	public function page()
 	{
+		$this->init($param);
 		if (!$this->refer) {
-			Dever::alert('没有回调url');
+			Dever::alert('没有回调refer');
 		}
 		return $this->method->page($this->get(1), $this->refer);
 	}
@@ -45,6 +57,7 @@ class Api
 	 */
 	public function qrcode()
 	{
+		$this->init($param);
 		$url = $this->method->qrcode($this->get(2), $this->refer);
 		Dever::apply('sdk/qrcode');
 		return \QRcode::png($url);
@@ -57,6 +70,9 @@ class Api
 	 */
 	private function init($param = array())
 	{
+		if (isset($this->account_id)) {
+			return;
+		}
 		$this->account_id = $this->getParam($param, 'account_id');
 		$this->uid = $this->getParam($param, 'uid');
 		$this->username = $this->getParam($param, 'username');