Ver Fonte

支付宝的wap支付方式,表单改链接

lizhen_gitee há 1 ano atrás
pai
commit
38ddfd2d06

+ 8 - 3
addons/epay/library/Yansongda/Pay/Gateways/Alipay.php

@@ -151,10 +151,11 @@ class Alipay implements GatewayApplicationInterface
 
         $this->payload['biz_content'] = json_encode($params);
 
+        $method = $gateway;
         $gateway = get_class($this).'\\'.Str::studly($gateway).'Gateway';
 
         if (class_exists($gateway)) {
-            return $this->makePay($gateway);
+            return $this->makePay($gateway,$method);
         }
 
         throw new InvalidGatewayException("Pay Gateway [{$gateway}] not exists");
@@ -368,10 +369,14 @@ class Alipay implements GatewayApplicationInterface
      *
      * @return Response|Collection
      */
-    protected function makePay(string $gateway)
+    protected function makePay(string $gateway, $method = '')
     {
         $app = new $gateway();
-
+        if ($method == 'wap') {
+            return $app->pay_wap($this->gateway, array_filter($this->payload, function ($value) {
+                return '' !== $value && !is_null($value);
+            }));
+        }
         if ($app instanceof GatewayInterface) {
             return $app->pay($this->gateway, array_filter($this->payload, function ($value) {
                 return '' !== $value && !is_null($value);

+ 44 - 0
addons/epay/library/Yansongda/Pay/Gateways/Alipay/WebGateway.php

@@ -42,6 +42,36 @@ class WebGateway extends Gateway
     }
 
     /**
+     * Pay an order.
+     *
+     * @author yansongda <me@yansongda.cn>
+     *
+     * @param string $endpoint
+     *
+     * @throws InvalidConfigException
+     * @throws InvalidArgumentException
+     */
+    public function pay_wap($endpoint, array $payload)
+    {
+        $biz_array = json_decode($payload['biz_content'], true);
+        $biz_array['product_code'] = $this->getProductCode();
+
+        $method = $biz_array['http_method'] ?? 'POST';
+
+        unset($biz_array['http_method']);
+        if ((Alipay::MODE_SERVICE === $this->mode) && (!empty(Support::getInstance()->pid))) {
+            $biz_array['extend_params'] = is_array($biz_array['extend_params']) ? array_merge(['sys_service_provider_id' => Support::getInstance()->pid], $biz_array['extend_params']) : ['sys_service_provider_id' => Support::getInstance()->pid];
+        }
+        $payload['method'] = $this->getMethod();
+        $payload['biz_content'] = json_encode($biz_array);
+        $payload['sign'] = Support::generateSign($payload);
+
+        Events::dispatch(new Events\PayStarted('Alipay', 'Web/Wap', $endpoint, $payload));
+
+        return $this->buildPayHtml_wap($endpoint, $payload, $method);
+    }
+
+    /**
      * Find.
      *
      * @author yansongda <me@yansongda.cn>
@@ -83,6 +113,20 @@ class WebGateway extends Gateway
     }
 
     /**
+     * Build Html response.
+     *
+     * @author yansongda <me@yansongda.cn>
+     *
+     * @param string $endpoint
+     * @param array  $payload
+     * @param string $method
+     */
+    protected function buildPayHtml_wap($endpoint, $payload, $method = 'POST')
+    {
+        return $endpoint.'&'.http_build_query($payload);
+    }
+
+    /**
      * Get method config.
      *
      * @author yansongda <me@yansongda.cn>