소스 검색

调试招商银行的回调事件

stanley-king 8 년 전
부모
커밋
4f51c8117f
7개의 변경된 파일145개의 추가작업 그리고 26개의 파일을 삭제
  1. 45 1
      helper/algorithm.php
  2. 4 2
      helper/pay/cmbpay.php
  3. 3 1
      helper/search/processor.php
  4. 42 20
      helper/search/searcher.php
  5. 20 0
      helper/search/tcp_client.php
  6. 21 0
      mobile/control/pay_return.php
  7. 10 2
      test/TestSearch.php

+ 45 - 1
helper/algorithm.php

@@ -99,7 +99,7 @@ class algorithm
         return array_splice($arr,$pos,1);
     }
 
-    static function intersection($ar1,$ar2)
+    static function set_intersection($ar1, $ar2)
     {
         $count1 = count($ar1);
         $count2 = count($ar2);
@@ -126,4 +126,48 @@ class algorithm
         }
         return $result;
     }
+
+    private static function copy($src,$pos,&$result)
+    {
+        $count = count($src);
+        for (;$pos < $count;++$pos) {
+            $result[] = $src[$pos];
+        }
+
+        return $result;
+    }
+
+    static function set_union($ar1,$ar2)
+    {
+        $count1 = count($ar1);
+        $count2 = count($ar2);
+        $pos1 = 0;
+        $pos2 = 0;
+
+        $result = [];
+        for (; $pos1 != $count1; )
+        {
+            if ($pos2 == $count2) {
+                return self::copy($ar1, $pos1, $result);
+            }
+
+            if ($ar1[$pos1] > $ar2[$pos2])
+            {
+                $result[] = $ar2[$pos2];
+                ++$pos2;
+            }
+            elseif($ar1[$pos1] == $ar2[$pos2]) {
+                $result[] = $ar1[$pos1];
+                ++$pos1;
+                ++$pos2;
+            }
+            else
+            {
+                $result[] = $ar1[$pos1];
+                ++$pos1;
+            }
+        }
+
+        return self::copy($ar2,$pos2,$result);
+    }
 }

+ 4 - 2
helper/pay/cmbpay.php

@@ -128,7 +128,8 @@ class cmbpay implements IPay
     const pay_url = 'http://61.144.248.29:801/netpayment/BaseHttp.dll?PrePayEUserP';
 
     const notify_signurl = BASE_SITE_URL . '/mobile/cmbpay_sign.php';
-    const notify_payurl = BASE_SITE_URL . '/mobile/cmbpay_notify.php';
+    const notify_payurl  = BASE_SITE_URL . '/mobile/cmbpay_notify.php';
+    const app_returl     = BASE_SITE_URL . '/mobile/index.php?act=pay_return&op=cmbpay';
 
     const debug_notify_signurl = 'http://121.43.114.153/mobile/cmbpay_sign.php';
     const debug_notify_payurl  = 'http://121.43.114.153/mobile/cmbpay_notify.php';
@@ -186,7 +187,8 @@ class cmbpay implements IPay
             'MerchantUrl' => self::pay_notify_url(),
             'MerchantPara' => $attach,
             'MerchantCode' => $code,
-            'MerchantRetUrl' => "",
+            'MerchantRetUrl' => self::app_returl,
+            'MerchantRetPara' => $attach
         ];
 
         $count = count($data);

+ 3 - 1
helper/search/processor.php

@@ -29,7 +29,9 @@ class processor implements IProcessor
             return serialize($result);
         }
         else if($type == self::SearchReasult) {
-
+            $words = $param['keyword'];
+            $result = searcher::instance()->get_result($words);
+            return serialize($result);
         }
         else {
 

+ 42 - 20
helper/search/searcher.php

@@ -254,25 +254,7 @@ class searcher
             return array();
         }
 
-        $i = 0;
-        $ids = [];
-        foreach ($words as $word)
-        {
-            $ids = $dict->find($word);
-            if($i == 0) {
-                $ids = $ids;
-            }
-            else
-            {
-                $tmp = algorithm::intersection($ids,$ids);
-                $ids = $tmp;
-
-                if(empty($ids)) {
-                    break;
-                }
-            }
-            ++$i;
-        }
+        $ids = $this->get_ids($dict, $words);
 
         $result = [];
         foreach ($ids as $id) {
@@ -303,8 +285,48 @@ class searcher
         return $result;
     }
 
-    public function get_result($key)
+    public function get_result($input)
     {
+        $words = [];
+        foreach (mb_str_split($input) as $word)
+        {
+            if(filter::filter($word)) {
+                $words[] = $word;
+            }
+        }
+        $name_ids = $this->get_ids($this->name_dict,$words);
+        $jin_ids = $this->get_ids($this->jingle_dict,$words);
+        $goods_ids = algorithm::set_union($name_ids,$jin_ids);
+
+        $brands = $this->get_ids($this->brand_dict,$words);
+        $hot_ids = $this->get_ids($this->category_dict,$words);
+
+        return array("brands" => $brands,"category" => $hot_ids,"goods" => $goods_ids);
+    }
 
+    /**
+     * @param $dict
+     * @param $words
+     * @return array
+     */
+    private function get_ids($dict, $words)
+    {
+        $i = 0;
+        $ids = [];
+        foreach ($words as $word) {
+            $ids = $dict->find($word);
+            if ($i == 0) {
+                $ids = $ids;
+            } else {
+                $tmp = algorithm::set_intersection($ids, $ids);
+                $ids = $tmp;
+
+                if (empty($ids)) {
+                    break;
+                }
+            }
+            ++$i;
+        }
+        return $ids;
     }
 }

+ 20 - 0
helper/search/tcp_client.php

@@ -55,6 +55,26 @@ class tcp_client
         return false;
     }
 
+    public function get_result($word)
+    {
+        if($this->init_socket() == false) {
+            return false;
+        }
+
+        $param = array("type" => processor::SearchReasult, "keyword" => $word);
+        $ret = $this->write_param($param);
+
+        if($ret == true)
+        {
+            $body = $this->read_body();
+            if($body != false) {
+                return unserialize($body);
+            }
+        }
+        $this->fini_socket();
+        return false;
+    }
+
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     private function init_socket()
     {

+ 21 - 0
mobile/control/pay_return.php

@@ -0,0 +1,21 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 2016/10/17
+ * Time: 下午4:42
+ */
+
+
+class pay_returnControl extends mobileHomeControl
+{
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    public function cmbpayOp()
+    {
+        Log::record("{pay_return: cmbpay}");
+    }
+}

+ 10 - 2
test/TestSearch.php

@@ -33,12 +33,12 @@ class TestSearch extends PHPUnit_Framework_TestCase
     public function testSearcher()
     {
         $searcher = new search\searcher();
-        $result = $searcher->get_word('眼光影');
+        $result = $searcher->get_result('眼光影');
     }
 
     public function testRequest()
     {
-        $result = search\tcp_client::instance()->get_words('眼光影');
+        $result = search\tcp_client::instance()->get_result('眼影');
     }
 
     public function testUasort()
@@ -54,4 +54,12 @@ class TestSearch extends PHPUnit_Framework_TestCase
         }
     }
 
+    public function testUnion()
+    {
+        $a1 = array(1,3,5,7,9);
+        $a2 = array(1,2,3,5,8,9);
+
+        $result = algorithm::set_union($a1,$a2);
+    }
+
 }