Parcourir la source

Merge branch 'raccount' into rchannel

xiaoyu il y a 3 ans
Parent
commit
c5f87b461a

+ 42 - 42
data/config/xyz/refill.ini.php

@@ -1951,27 +1951,27 @@ $xinhengyang_phone = ['name' => 'xinhengyang', 'store_id' => 100, 'qualitys' =>
 //        20 => [['goods_id' => 6894, 'price' => 19.12, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
         30 => [
             ['goods_id' => 6895, 'price' => 28.77, 'quality' => 1, 'card_type' => 'chinamobile'],
-            ['goods_id' => 6895, 'price' => 28.26, 'quality' => 1, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 6895, 'price' => 28.35, 'quality' => 1, 'card_type' => 'chinaunicom'],
             ['goods_id' => 6895, 'price' => 28.62, 'quality' => 1, 'card_type' => 'chinatelecom']
         ],
         50 => [
             ['goods_id' => 6896, 'price' => 47.95, 'quality' => 1, 'card_type' => 'chinamobile'],
-            ['goods_id' => 6896, 'price' => 47.1, 'quality' => 1, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 6896, 'price' => 47.25, 'quality' => 1, 'card_type' => 'chinaunicom'],
             ['goods_id' => 6896, 'price' => 47.7, 'quality' => 1, 'card_type' => 'chinatelecom']
         ],
         100 => [
             ['goods_id' => 6897, 'price' => 95.9, 'quality' => 1, 'card_type' => 'chinamobile'],
-            ['goods_id' => 6897, 'price' => 94.2, 'quality' => 1, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 6897, 'price' => 94.5, 'quality' => 1, 'card_type' => 'chinaunicom'],
             ['goods_id' => 6897, 'price' => 95.4, 'quality' => 1, 'card_type' => 'chinatelecom']
         ],
         200 => [
             ['goods_id' => 6898, 'price' => 191.8, 'quality' => 1, 'card_type' => 'chinamobile'],
-            ['goods_id' => 6898, 'price' => 188.4, 'quality' => 1, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 6898, 'price' => 189, 'quality' => 1, 'card_type' => 'chinaunicom'],
             ['goods_id' => 6898, 'price' => 190.8, 'quality' => 1, 'card_type' => 'chinatelecom']
         ],
         300 => [
             ['goods_id' => 6899, 'price' => 287.7, 'quality' => 1, 'card_type' => 'chinamobile'],
-            ['goods_id' => 6899, 'price' => 282.6, 'quality' => 1, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 6899, 'price' => 283.5, 'quality' => 1, 'card_type' => 'chinaunicom'],
             ['goods_id' => 6899, 'price' => 286.2, 'quality' => 1, 'card_type' => 'chinatelecom']
         ],
 //        500 => [['goods_id' => 6900, 'price' => 478, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']]
@@ -2582,27 +2582,27 @@ $guochuang_nation_phone = ['name' => 'guochuang_nation', 'store_id' => 121, 'qua
         ],
         30 => [
             ['goods_id' => 7062, 'price' => 30.33, 'quality' => 2, 'card_type' => 'chinamobile'],
-            ['goods_id' => 7062, 'price' => 30.03, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7062, 'price' => 29.985, 'quality' => 2, 'card_type' => 'chinaunicom'],
             ['goods_id' => 7062, 'price' => 30.33, 'quality' => 2, 'card_type' => 'chinatelecom']
         ],
         50 => [
             ['goods_id' => 7063, 'price' => 50.125, 'quality' => 2, 'card_type' => 'chinamobile'],
-            ['goods_id' => 7063, 'price' => 50.05, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7063, 'price' => 49.975, 'quality' => 2, 'card_type' => 'chinaunicom'],
             ['goods_id' => 7063, 'price' => 50.35, 'quality' => 2, 'card_type' => 'chinatelecom']
         ],
         100 => [
             ['goods_id' => 7064, 'price' => 100.2, 'quality' => 2, 'card_type' => 'chinamobile'],
-            ['goods_id' => 7064, 'price' => 100.1, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7064, 'price' => 99.95, 'quality' => 2, 'card_type' => 'chinaunicom'],
             ['goods_id' => 7064, 'price' => 100.4, 'quality' => 2, 'card_type' => 'chinatelecom']
         ],
         200 => [
             ['goods_id' => 7065, 'price' => 200.4, 'quality' => 2, 'card_type' => 'chinamobile'],
-            ['goods_id' => 7065, 'price' => 200.2, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7065, 'price' => 199.9, 'quality' => 2, 'card_type' => 'chinaunicom'],
             ['goods_id' => 7065, 'price' => 200.46, 'quality' => 2, 'card_type' => 'chinatelecom']
         ],
         300 => [
             ['goods_id' => 7066, 'price' => 300.6, 'quality' => 2, 'card_type' => 'chinamobile'],
-            ['goods_id' => 7066, 'price' => 300.3, 'quality' => 2, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7066, 'price' => 299.85, 'quality' => 2, 'card_type' => 'chinaunicom'],
             ['goods_id' => 7066, 'price' => 300.69, 'quality' => 2, 'card_type' => 'chinatelecom']
         ],
         500 => [
@@ -2809,12 +2809,12 @@ $yuanta_phone = ['name' => 'yuanta', 'store_id' => 128, 'qualitys' => '5',
         100 => [
 //            ['goods_id' => 7120, 'price' => 91.8, 'quality' => 5, 'card_type' => 'chinamobile'],
             ['goods_id' => 7120, 'price' => 90.3, 'quality' => 5, 'card_type' => 'chinaunicom'],
-//            ['goods_id' => 7120, 'price' => 95.6, 'quality' => 5, 'card_type' => 'chinatelecom']
+            ['goods_id' => 7120, 'price' => 92.5, 'quality' => 5, 'card_type' => 'chinatelecom']
         ],
         200 => [
 //            ['goods_id' => 7121, 'price' => 183.6, 'quality' => 5, 'card_type' => 'chinamobile'],
             ['goods_id' => 7121, 'price' => 180.6, 'quality' => 5, 'card_type' => 'chinaunicom'],
-//            ['goods_id' => 7121, 'price' => 191.2, 'quality' => 5, 'card_type' => 'chinatelecom']
+            ['goods_id' => 7121, 'price' => 185, 'quality' => 5, 'card_type' => 'chinatelecom']
         ]
 //        300 => [
 //            ['goods_id' => 7122, 'price' => 275.4, 'quality' => 5, 'card_type' => 'chinamobile'],
@@ -2989,22 +2989,22 @@ $xingzy_normal_phone = ['name' => 'xingzy_normal', 'store_id' => 137, 'qualitys'
         30 => [
             ['goods_id' => 7181, 'price' => 28.65, 'quality' => 1, 'card_type' => 'chinamobile'],
             ['goods_id' => 7181, 'price' => 28.47, 'quality' => 1, 'card_type' => 'chinaunicom'],
-            ['goods_id' => 7181, 'price' => 28.89, 'quality' => 1, 'card_type' => 'chinatelecom']
+            ['goods_id' => 7181, 'price' => 28.65, 'quality' => 1, 'card_type' => 'chinatelecom']
         ],
         50 => [
             ['goods_id' => 7182, 'price' => 47.75, 'quality' => 1, 'card_type' => 'chinamobile'],
             ['goods_id' => 7182, 'price' => 47.45, 'quality' => 1, 'card_type' => 'chinaunicom'],
-            ['goods_id' => 7182, 'price' => 48.15, 'quality' => 1, 'card_type' => 'chinatelecom']
+            ['goods_id' => 7182, 'price' => 47.75, 'quality' => 1, 'card_type' => 'chinatelecom']
         ],
         100 => [
             ['goods_id' => 7183, 'price' => 95.5, 'quality' => 1, 'card_type' => 'chinamobile'],
             ['goods_id' => 7183, 'price' => 94.9, 'quality' => 1, 'card_type' => 'chinaunicom'],
-            ['goods_id' => 7183, 'price' => 96.3, 'quality' => 1, 'card_type' => 'chinatelecom']
+            ['goods_id' => 7183, 'price' => 95.5, 'quality' => 1, 'card_type' => 'chinatelecom']
         ],
         200 => [
             ['goods_id' => 7184, 'price' => 191, 'quality' => 1, 'card_type' => 'chinamobile'],
             ['goods_id' => 7184, 'price' => 189.8, 'quality' => 1, 'card_type' => 'chinaunicom'],
-            ['goods_id' => 7184, 'price' => 192.6, 'quality' => 1, 'card_type' => 'chinatelecom']
+            ['goods_id' => 7184, 'price' => 191, 'quality' => 1, 'card_type' => 'chinatelecom']
         ],
 //        300 => [['goods_id' => 7185, 'price' => 286.5, 'quality' => 1, 'card_type' => 'chinaunicom,chinatelecom']],
 //        500 => [['goods_id' => 7186, 'price' => 477.5, 'quality' => 1, 'card_type' => 'chinaunicom,chinatelecom']]
@@ -3235,22 +3235,22 @@ $dashang_normal_phone = ['name' => 'dashang_normal', 'store_id' => 148, 'quality
         30 => [
             ['goods_id' => 7269, 'price' => 29.19, 'quality' => 1, 'card_type' => 'chinamobile'],
             ['goods_id' => 7269, 'price' => 28.44, 'quality' => 1, 'card_type' => 'chinaunicom'],
-            ['goods_id' => 7269, 'price' => 28.74, 'quality' => 1, 'card_type' => 'chinatelecom'],
+            ['goods_id' => 7269, 'price' => 28.65, 'quality' => 1, 'card_type' => 'chinatelecom'],
         ],
         50 => [
             ['goods_id' => 7270, 'price' => 48.15, 'quality' => 1, 'card_type' => 'chinamobile'],
             ['goods_id' => 7270, 'price' => 47.4, 'quality' => 1, 'card_type' => 'chinaunicom'],
-            ['goods_id' => 7270, 'price' => 47.9, 'quality' => 1, 'card_type' => 'chinatelecom']
+            ['goods_id' => 7270, 'price' => 47.75, 'quality' => 1, 'card_type' => 'chinatelecom']
         ],
         100 => [
             ['goods_id' => 7271, 'price' => 96.3, 'quality' => 1, 'card_type' => 'chinamobile'],
             ['goods_id' => 7271, 'price' => 94.8, 'quality' => 1, 'card_type' => 'chinaunicom'],
-            ['goods_id' => 7271, 'price' => 95.8, 'quality' => 1, 'card_type' => 'chinatelecom']
+            ['goods_id' => 7271, 'price' => 95.5, 'quality' => 1, 'card_type' => 'chinatelecom']
         ],
         200 => [
             ['goods_id' => 7272, 'price' => 192.6, 'quality' => 1, 'card_type' => 'chinamobile'],
             ['goods_id' => 7272, 'price' => 189.6, 'quality' => 1, 'card_type' => 'chinaunicom'],
-            ['goods_id' => 7272, 'price' => 191.6, 'quality' => 1, 'card_type' => 'chinatelecom']
+            ['goods_id' => 7272, 'price' => 191, 'quality' => 1, 'card_type' => 'chinatelecom']
         ],
         300 => [
             ['goods_id' => 7273, 'price' => 284.4, 'quality' => 1, 'card_type' => 'chinaunicom']
@@ -3368,22 +3368,22 @@ $guantu_phone = ['name' => 'guantu', 'store_id' => 157, 'qualitys' => '1',
         30 => [
             ['goods_id' => 7327, 'price' => 28.86, 'quality' => 1, 'card_type' => 'chinamobile'],
             ['goods_id' => 7327, 'price' => 28.44, 'quality' => 1, 'card_type' => 'chinaunicom'],
-            ['goods_id' => 7327, 'price' => 28.65, 'quality' => 1, 'card_type' => 'chinatelecom']
+            ['goods_id' => 7327, 'price' => 28.5, 'quality' => 1, 'card_type' => 'chinatelecom']
         ],
         50 => [
             ['goods_id' => 7328, 'price' => 48.1, 'quality' => 1, 'card_type' => 'chinamobile'],
             ['goods_id' => 7328, 'price' => 47.4, 'quality' => 1, 'card_type' => 'chinaunicom'],
-            ['goods_id' => 7328, 'price' => 47.75, 'quality' => 1, 'card_type' => 'chinatelecom'],
+            ['goods_id' => 7328, 'price' => 47.5, 'quality' => 1, 'card_type' => 'chinatelecom'],
         ],
         100 => [
             ['goods_id' => 7329, 'price' => 96.2, 'quality' => 1, 'card_type' => 'chinamobile'],
             ['goods_id' => 7329, 'price' => 94.8, 'quality' => 1, 'card_type' => 'chinaunicom'],
-            ['goods_id' => 7329, 'price' => 95.5, 'quality' => 1, 'card_type' => 'chinatelecom']
+            ['goods_id' => 7329, 'price' => 95, 'quality' => 1, 'card_type' => 'chinatelecom']
         ],
         200 => [
             ['goods_id' => 7330, 'price' => 192.4, 'quality' => 1, 'card_type' => 'chinamobile'],
             ['goods_id' => 7330, 'price' => 189.6, 'quality' => 1, 'card_type' => 'chinaunicom'],
-            ['goods_id' => 7330, 'price' => 191, 'quality' => 1, 'card_type' => 'chinatelecom']
+            ['goods_id' => 7330, 'price' => 190, 'quality' => 1, 'card_type' => 'chinatelecom']
         ],
         300 => [
 //            ['goods_id' => 7331, 'price' => 288, 'quality' => 1, 'card_type' => 'chinamobile'],
@@ -3938,22 +3938,22 @@ $ruixunda_phone = ['name' => 'ruixunda', 'store_id' => 169, 'qualitys' => '1',
         30 => [
 //            ['goods_id' => 7441, 'price' => 28.86, 'quality' => 1, 'card_type' => 'chinamobile'],
             ['goods_id' => 7441, 'price' => 28.35, 'quality' => 1, 'card_type' => 'chinaunicom'],
-            ['goods_id' => 7441, 'price' => 28.56, 'quality' => 1, 'card_type' => 'chinatelecom']
+            ['goods_id' => 7441, 'price' => 28.38, 'quality' => 1, 'card_type' => 'chinatelecom']
         ],
         50 => [
 //            ['goods_id' => 7442, 'price' => 48.1, 'quality' => 1, 'card_type' => 'chinamobile'],
             ['goods_id' => 7442, 'price' => 47.25, 'quality' => 1, 'card_type' => 'chinaunicom'],
-            ['goods_id' => 7442, 'price' => 47.6, 'quality' => 1, 'card_type' => 'chinatelecom']
+            ['goods_id' => 7442, 'price' => 47.3, 'quality' => 1, 'card_type' => 'chinatelecom']
         ],
         100 => [
 //            ['goods_id' => 7443, 'price' => 96.2, 'quality' => 1, 'card_type' => 'chinamobile'],
             ['goods_id' => 7443, 'price' => 94.5, 'quality' => 1, 'card_type' => 'chinaunicom'],
-            ['goods_id' => 7443, 'price' => 95.2, 'quality' => 1, 'card_type' => 'chinatelecom']
+            ['goods_id' => 7443, 'price' => 94.6, 'quality' => 1, 'card_type' => 'chinatelecom']
         ],
         200 => [
 //            ['goods_id' => 7444, 'price' => 192.4, 'quality' => 1, 'card_type' => 'chinamobile'],
             ['goods_id' => 7444, 'price' => 189, 'quality' => 1, 'card_type' => 'chinaunicom'],
-            ['goods_id' => 7444, 'price' => 190.4, 'quality' => 1, 'card_type' => 'chinatelecom']
+            ['goods_id' => 7444, 'price' => 189.2, 'quality' => 1, 'card_type' => 'chinatelecom']
         ],
         300 => [
 //            ['goods_id' => 7445, 'price' => 286.5, 'quality' => 1, 'card_type' => 'chinamobile'],
@@ -4408,22 +4408,22 @@ $chizeng_normal_phone = ['name' => 'chizeng_normal', 'store_id' => 182,'qualitys
         30 => [
             ['goods_id' => 7538, 'price' => 28.74, 'quality' => 1, 'card_type' => 'chinamobile'],
             ['goods_id' => 7538, 'price' => 28.65, 'quality' => 1, 'card_type' => 'chinaunicom'],
-            ['goods_id' => 7538, 'price' => 28.65, 'quality' => 1, 'card_type' => 'chinatelecom']
+            ['goods_id' => 7538, 'price' => 28.59, 'quality' => 1, 'card_type' => 'chinatelecom']
         ],
         50 => [
             ['goods_id' => 7539, 'price' => 47.75, 'quality' => 1, 'card_type' => 'chinamobile'],
             ['goods_id' => 7539, 'price' => 47.75, 'quality' => 1, 'card_type' => 'chinaunicom'],
-            ['goods_id' => 7539, 'price' => 47.75, 'quality' => 1, 'card_type' => 'chinatelecom']
+            ['goods_id' => 7539, 'price' => 47.65, 'quality' => 1, 'card_type' => 'chinatelecom']
         ],
         100 => [
             ['goods_id' => 7540, 'price' => 95.5, 'quality' => 1, 'card_type' => 'chinamobile'],
             ['goods_id' => 7540, 'price' => 95.5, 'quality' => 1, 'card_type' => 'chinaunicom'],
-            ['goods_id' => 7540, 'price' => 95.5, 'quality' => 1, 'card_type' => 'chinatelecom']
+            ['goods_id' => 7540, 'price' => 95.3, 'quality' => 1, 'card_type' => 'chinatelecom']
         ],
         200 => [
             ['goods_id' => 7541, 'price' => 191, 'quality' => 1, 'card_type' => 'chinamobile'],
             ['goods_id' => 7541, 'price' => 191, 'quality' => 1, 'card_type' => 'chinaunicom'],
-            ['goods_id' => 7541, 'price' => 191, 'quality' => 1, 'card_type' => 'chinatelecom']
+            ['goods_id' => 7541, 'price' => 190.6, 'quality' => 1, 'card_type' => 'chinatelecom']
         ],
         300 => [
             ['goods_id' => 7542, 'price' => 287.4, 'quality' => 1, 'card_type' => 'chinamobile'],
@@ -4452,28 +4452,28 @@ $xinhengyangnew_phone = ['name' => 'xinhengyangnew', 'store_id' => 183,'qualitys
 //        ],
         30 => [
             ['goods_id' => 7555, 'price' => 28.77, 'quality' => 1, 'card_type' => 'chinamobile'],
-            ['goods_id' => 7555, 'price' => 28.47, 'quality' => 1, 'card_type' => 'chinaunicom'],
-            ['goods_id' => 7555, 'price' => 28.77, 'quality' => 1, 'card_type' => 'chinatelecom']
+            ['goods_id' => 7555, 'price' => 28.35, 'quality' => 1, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7555, 'price' => 28.71, 'quality' => 1, 'card_type' => 'chinatelecom']
         ],
         50 => [
             ['goods_id' => 7556, 'price' => 47.95, 'quality' => 1, 'card_type' => 'chinamobile'],
-            ['goods_id' => 7556, 'price' => 47.45, 'quality' => 1, 'card_type' => 'chinaunicom'],
-            ['goods_id' => 7556, 'price' => 47.95, 'quality' => 1, 'card_type' => 'chinatelecom']
+            ['goods_id' => 7556, 'price' => 47.25, 'quality' => 1, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7556, 'price' => 47.85, 'quality' => 1, 'card_type' => 'chinatelecom']
         ],
         100 => [
             ['goods_id' => 7557, 'price' => 95.9, 'quality' => 1, 'card_type' => 'chinamobile'],
-            ['goods_id' => 7557, 'price' => 94.9, 'quality' => 1, 'card_type' => 'chinaunicom'],
-            ['goods_id' => 7557, 'price' => 95.9, 'quality' => 1, 'card_type' => 'chinatelecom']
+            ['goods_id' => 7557, 'price' => 94.5, 'quality' => 1, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7557, 'price' => 95.7, 'quality' => 1, 'card_type' => 'chinatelecom']
         ],
         200 => [
             ['goods_id' => 7558, 'price' => 191.8, 'quality' => 1, 'card_type' => 'chinamobile'],
-            ['goods_id' => 7558, 'price' => 189.8, 'quality' => 1, 'card_type' => 'chinaunicom'],
-            ['goods_id' => 7558, 'price' => 191.8, 'quality' => 1, 'card_type' => 'chinatelecom']
+            ['goods_id' => 7558, 'price' => 189, 'quality' => 1, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7558, 'price' => 191.4, 'quality' => 1, 'card_type' => 'chinatelecom']
         ],
         300 => [
             ['goods_id' => 7559, 'price' => 287.7, 'quality' => 1, 'card_type' => 'chinamobile'],
-            ['goods_id' => 7559, 'price' => 284.7, 'quality' => 1, 'card_type' => 'chinaunicom'],
-            ['goods_id' => 7559, 'price' => 287.7, 'quality' => 1, 'card_type' => 'chinatelecom']
+            ['goods_id' => 7559, 'price' => 283.5, 'quality' => 1, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7559, 'price' => 287.1, 'quality' => 1, 'card_type' => 'chinatelecom']
         ],
 //        500 => [
 //            ['goods_id' => 7560, 'price' => 477, 'quality' => 1, 'card_type' => 'chinamobile'],

+ 382 - 0
helper/mtopcard/card_query.php

@@ -0,0 +1,382 @@
+<?php
+
+namespace mtopcard;
+
+use Log;
+
+class card_query
+{
+    private function validate_checker($status)
+    {
+        // "status": 1 //状态 0:空号;1:实号;2:停机;3:库无;4:沉默号;5:风险号 6: 未知 7: 流量卡
+        Log::record("status={$status}",Log::DEBUG);
+        if (in_array($status, [0, 5, 7])) {
+            return false;
+        } else {
+            return true;
+        }
+    }
+
+    //[success,$card_type,$region_no,$isTransfer,$status]
+    private function tencent_query($card_no)
+    {
+        $type_checker = function ($channel)
+        {
+            if($channel == 'CMCC') {
+                return ChinaMobileCard;
+            }
+            elseif($channel == 'CTCC') {
+                return ChinaTelecomCard;
+            }
+            elseif($channel == 'CUCC') {
+                return ChinaUnicomCard;
+            }
+            else {
+                return UnknownCard;
+            }
+        };
+
+        $status_converter = function ($code)
+        {
+            // "status": 1 //状态 0:空号;1:实号;2:停机;3:库无;4:沉默号;5:风险号 6: 未知 7: 流量卡
+            if($code === 1) {
+                return 1;
+            } elseif($code === 2) {
+                return 0;
+            } elseif ($code === 3) {
+                return 2;
+            } elseif ($code === 4) {
+                return 7;
+            } elseif($code === 5) {
+                return 4;
+            } else {
+                return 6;
+            }
+        };
+
+        $regin_checker = function ($province)
+        {
+            if(empty($province)) return -1;
+            $endtxts= ["省","市","自治区","特别行政区"];
+
+            foreach ($endtxts as $endtxt)
+            {
+                if(strpos($province, $endtxt) === false) {
+                    continue;
+                } else {
+                    $province = mb_strcut($province, 0, strrpos($province, $endtxt));
+                }
+            }
+
+            if(array_key_exists($province,Prov2Noes)) {
+                return Prov2Noes[$province];
+            } else {
+                return -1;
+            }
+        };
+
+        $query_fun = function ($card_no, &$card_type, &$region_no, &$status) use ($type_checker, $regin_checker, $status_converter)
+        {
+            $secretId = 'AKIDkd6sT6C4765LtYN1W2fN2WC2Ynr42acemjQW';
+            $secretKey = 'dupQeU838dhuQ8uDP2bi81nQNb5wt9KW1qLP7eWu';
+            $source = 'market';
+
+            // 签名
+            $datetime = gmdate('D, d M Y H:i:s T');
+            $signStr = sprintf("x-date: %s\nx-source: %s", $datetime, $source);
+            $sign = base64_encode(hash_hmac('sha1', $signStr, $secretKey, true));
+            $auth = sprintf('hmac id="%s", algorithm="hmac-sha1", headers="x-date x-source", signature="%s"', $secretId, $sign);
+            $header = [
+                "X-Source: {$source}",
+                "X-Date: {$datetime}",
+                "Authorization: {$auth}",
+            ];
+            $data['number'] = $card_no;
+            $url = 'https://service-empgc6lp-1256724964.sh.apigw.tencentcs.com/release/query';
+            $net_err = 0;
+            $resp = http_request($url, $data, 'GET',false, $header,$net_err);
+
+            if ($resp == false) return false;
+
+            $resp = json_decode($resp, true);
+            if ($resp == false) return false;
+
+            if ($resp['ret'] == 200)
+            {
+                $data = $resp['data'];
+                $code = intval($data['code']);
+                $extend = $data['extend'];
+
+                $status = $status_converter($code);
+                $card_type = $type_checker($extend['isp']);
+                $region_no = $regin_checker($extend['prov']);
+                return true;
+            } else {
+                Log::record("tencent_valid phone:{$card_no}", Log::DEBUG);
+                return false;
+            }
+        };
+
+        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+        $org_type = card_type($card_no,$region_no);
+        $region_no = -1;
+        $status = 6;
+
+        //[succ,$card_type,$region_no,$isTransfer,$status]
+        $ret = $query_fun($card_no, $card_type, $region_no, $status);
+        if ($ret) {
+            $isTransfer = $org_type != $card_type;
+            return [true, $card_type, $region_no, $isTransfer, $status];
+        }
+        else {
+            return [false, $card_type, -1, false, $status];
+        }
+    }
+
+    //[succ,$card_type,$region_no,$isTransfer,$status]
+    public function tianyan_query($card_no)
+    {
+        $type_checker = function ($channel)
+        {
+            if($channel == '联通') {
+                return ChinaUnicomCard;
+            }
+            elseif($channel == '电信') {
+                return ChinaTelecomCard;
+            }
+            elseif($channel == '移动') {
+                return ChinaMobileCard;
+            }
+            else {
+                return UnknownCard;
+            }
+        };
+
+        $regin_checker = function ($area)
+        {
+            if(empty($area)) return -1;
+            $areas = explode('-',$area);
+            if(count($areas) > 0)
+            {
+                $province = $areas[0];
+                $endtxts= ["省","市","自治区","特别行政区"];
+
+                foreach ($endtxts as $endtxt)
+                {
+                    if(strpos($province, $endtxt) === false) {
+                        continue;
+                    } else {
+                        $province = mb_strcut($province, 0, strrpos($province, $endtxt));
+                    }
+                }
+
+                if(array_key_exists($province,Prov2Noes)) {
+                    return Prov2Noes[$province];
+                }
+            }
+
+            return -1;
+        };
+
+        $ali = function ($card_no, &$region_no, &$status) use ($regin_checker): bool
+        {
+            $url = 'https://mobileempty.shumaidata.com/mobileempty';
+            $params['mobile'] = $card_no;
+            $headers = ["Authorization:APPCODE " . '8f92d951293f4d2ea48ff86d5a70c537'];
+
+            $net_err = 0;
+            $resp = http_request($url, $params, 'GET', false, $headers,$net_err);
+            if ($resp == false) return false;
+
+            $resp = json_decode($resp, true);
+            if ($resp == false) return false;
+
+            if ($resp['code'] == 200)
+            {
+                $data = $resp['data'];
+                $status = intval($data['status']);
+                $region_no = $regin_checker($data['area']);
+                return true;
+            } else {
+                Log::record("ali_valid phone:{$card_no} return msg:{$resp['msg']}", Log::DEBUG);
+                return false;
+            }
+        };
+
+        $tianyan = function ($card_no, &$region_no, &$status) use ($regin_checker): bool
+        {
+            $url = 'https://api.shumaidata.com/v4/mobile_empty/check';
+            $appid = '2Xfa6IFIPv0sVUjy';
+            $appSecurity = '2Xfa6IFIPv0sVUjynOddsfh6KXfbyJ84';
+            $cur = microtime (true);
+
+            $data['appid'] = $appid;
+            $data['timestamp'] = intval($cur * 1000);
+            $content = "{$appid}&{$data['timestamp']}&{$appSecurity}";
+            $data['sign'] = md5($content);
+            $data['mobile'] = $card_no;
+
+            $net_err = 0;
+            $resp = http_request($url, $data, 'GET',false, [],$net_err);
+            if ($resp == false) return false;
+
+            $resp = json_decode($resp, true);
+            if ($resp == false) return false;
+
+            if ($resp['code'] == 200)
+            {
+                $data = $resp['data'];
+                $status = intval($data['status']);
+                $region_no = $regin_checker($data['area']);
+                return true;
+            } else {
+                Log::record("tianyan_valid phone:{$card_no} return msg:{$resp['msg']}", Log::DEBUG);
+                return false;
+            }
+        };
+
+        $tianyan_cardtyper = function ($card_no) use ($type_checker)
+        {
+            $url = 'https://api.shumaidata.com/v4/mobile-transfer/query';
+            $appid = '2Xfa6IFIPv0sVUjy';
+            $appSecurity = '2Xfa6IFIPv0sVUjynOddsfh6KXfbyJ84';
+            $cur = microtime (true);
+
+            $data['appid'] = $appid;
+            $data['timestamp'] = intval($cur * 1000);
+            $content = "{$appid}&{$data['timestamp']}&{$appSecurity}";
+            $data['sign'] = md5($content);
+            $data['mobile'] = $card_no;
+
+            $net_err = 0;
+            $resp = http_request($url, $data, 'GET',false, [],$net_err);
+            if ($resp == false) return [false,UnknownCard,UnknownCard,false];
+
+            $resp = json_decode($resp, true);
+            if ($resp == false) return [false,UnknownCard,UnknownCard,false];
+
+            if ($resp['code'] == 200)
+            {
+                $data = $resp['data'];
+                $ispType = $data['ispType'];
+                $newIspType = $data['newIspType'];
+
+                $card_type = $type_checker($newIspType);
+                $org_type = $type_checker($ispType);
+                $isTransfer = $org_type != $card_type;
+
+                Log::record("tianyan_transfer phone:{$card_no} card_type={$card_type} ispType:{$ispType} newIspType:{$newIspType}", Log::DEBUG);
+                return [true,$card_type,$org_type,$isTransfer];
+            } else {
+                Log::record("tianyan_transfer phone:{$card_no} return msg:{$resp['msg']}", Log::DEBUG);
+                return [false,UnknownCard,UnknownCard,false];
+            }
+        };
+
+        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+        [$succ,$_card_type,$_org_type,$_isTransfer] = $tianyan_cardtyper($card_no);
+        if($succ) {
+            $card_type = $_card_type;
+            $org_type = $_org_type;
+            $isTransfer = $_isTransfer;
+        }
+        else {
+            $isTransfer = false;
+            $card_type = card_type($card_no,$region_no);
+        }
+
+        $status = 6;
+        $ret = $tianyan($card_no, $region_no, $status);
+        if ($ret) {
+            return [true, $card_type, $region_no, $isTransfer, $status];
+        }
+
+        $ret = $ali($card_no, $region_no, $status);
+        if ($ret) {
+            return [true, $card_type, $region_no, $isTransfer, $status];
+        }
+
+        return [false, $card_type, -1, false, $status];
+    }
+
+
+    //[$validate,$card_type,$region_no,$isTransfer,$status,$black]
+    public function validate($card_no)
+    {
+        $time_checker = function ($update_time)
+        {
+            //90 天以内数据有效
+            $delta = time() - intval($update_time);
+            return $delta < 360 * 86400 && $delta >= 0;
+        };
+
+        $pinfo_getter = function ($card_no) use ($time_checker)
+        {
+            $mod_card = Model('card_info');
+            $info = $mod_card->getCardInfo($card_no);
+
+            if(empty($info)) {
+                return [false,[]];
+            }
+            elseif($time_checker($info['update_time'])) {
+                $mod_card->where(['card_no' => $card_no])->update(['using_times' => $info['using_times'] + 1]);
+
+                $card_type = intval($info['card_type']);
+                $region_no = intval($info['regin']);
+                $isTransfer = !(intval($info['transfer']) == 0);
+                $status = intval($info['card_state']);
+                $black = intval($info['black']);
+                $validate = $this->validate_checker($status);
+                $result = [$validate,$card_type,$region_no,$isTransfer,$status,$black];
+                return [true,$result];
+            }
+            else {
+                return [false,[]];
+            }
+        };
+
+        $pinfo_updator = function ($card_no,$card_type,$org_type,$region_no,$isTransfer,$status)
+        {
+            $mod_card = Model('card_info');
+            $transfer = $isTransfer == true ? 1 : 0;
+            $mod_card->replace_card($card_no,$card_type,$org_type,$region_no,$transfer,$status);
+        };
+
+        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+        $validate = true;
+        $black = 0;
+
+        $org_type = card_type($card_no,$region_no);
+        $region_no = -1;
+
+        if($org_type === UnknownCard) {
+            return [false, $org_type, $region_no, false, 1, $black];
+        }
+
+        if($org_type == PetroChinaCard || $org_type == SinopecCard) {
+            return [$validate, $org_type, $region_no, false, 1, $black];
+        }
+
+        [$succ,$result] = $pinfo_getter($card_no);
+        if($succ) return $result;
+
+        [$succ,$card_type,$region_no,$isTransfer,$status] = $this->tianyan_query($card_no);
+        if($succ === false) {
+            return [true, $org_type, -1, false, 1, $black];
+        }
+
+//        [$succ,$card_type,$region_no,$isTransfer,$status] = $this->tencent_query($card_no);
+//        if($succ === false)
+//        {
+//            [$succ,$card_type,$region_no,$isTransfer,$status] = $this->tianyan_query($card_no);
+//            if($succ === false) {
+//                return [true, $org_type, -1, false, 1];
+//            }
+//        }
+
+        $validate = $this->validate_checker($status);
+        $pinfo_updator($card_no,$card_type,$org_type,$region_no,$isTransfer,$status);
+
+        return [$validate,$card_type,$region_no,$isTransfer,$status,$black];
+    }
+}

+ 58 - 346
helper/mtopcard/mtopcard.php

@@ -2,6 +2,12 @@
 
 namespace mtopcard;
 
+require_once(BASE_HELPER_PATH . '/mtopcard/card_query.php');
+require_once(BASE_HELPER_PATH . '/mtopcard/topcard.php');
+require_once(BASE_HELPER_PATH . '/mtopcard/user_topcards.php');
+require_once(BASE_HELPER_PATH . '/mtopcard/CardPaper.php');
+require_once(BASE_HELPER_PATH . '/mtopcard/cards_helper.php');
+
 use Log;
 
 #用户卡的类型
@@ -72,6 +78,40 @@ const ProvinceList = [
     31	=> '新疆'
 ];
 
+const Prov2Noes = [
+    '北京' => 1,
+    '天津' => 2,
+    '河北' => 3,
+    '山西' => 4,
+    '内蒙古' => 5,
+    '辽宁' => 6,
+    '吉林' => 7,
+    '黑龙江' => 8,
+    '上海' => 9,
+    '江苏' => 10,
+    '浙江' => 11,
+    '安徽' => 12,
+    '福建' => 13,
+    '江西' => 14,
+    '山东' => 15,
+    '河南' => 16,
+    '湖北' => 17,
+    '湖南' => 18,
+    '广东' => 19,
+    '广西' => 20,
+    '海南' => 21,
+    '重庆' => 22,
+    '四川' => 23,
+    '贵州' => 24,
+    '云南' => 25,
+    '西藏' => 26,
+    '陕西' => 27,
+    '甘肃' => 28,
+    '青海' => 29,
+    '宁夏' => 30,
+    '新疆' => 31,
+];
+
 #空号拦截状态
 const CardState = [
     0 => '空号',
@@ -150,11 +190,6 @@ function scard_type($card_type)
     }
 }
 
-require_once(BASE_HELPER_PATH . '/mtopcard/topcard.php');
-require_once(BASE_HELPER_PATH . '/mtopcard/user_topcards.php');
-require_once(BASE_HELPER_PATH . '/mtopcard/CardPaper.php');
-require_once(BASE_HELPER_PATH . '/mtopcard/cards_helper.php');
-
 function priority_cards($member_id, $page_type = '')
 {
     if($page_type == 'oil') {
@@ -189,11 +224,13 @@ function simple_card_type($cardno)
         return SinopecCard;
     } elseif (preg_match('/^9[0-9]{15}$/', $cardno, $matches)) {
         return PetroChinaCard;
-    } elseif (preg_match('/^134[0-8]\d{7}$|^(?:13[5-9]|147|15[0-27-9]|17[28]|18[2-478]|19[578])\d{8}$/', $cardno, $matches)) {
+    } elseif (preg_match('/^134[0-8]\d{7}$|^(?:13[5-9]|15[012789]|17[28]|18[23478]|19[578])\d{8}$/', $cardno, $matches)) {
         return ChinaMobileCard;
-    } elseif (preg_match('/^(?:13[0-2]|145|15[56]|166|17[156]|18[56]|196)\d{8}$/', $cardno, $matches)) {
+    } elseif (preg_match('/^(?:13[0-2]|15[56]|166|17[156]|18[56]|196)\d{8}$/', $cardno, $matches)) {
         return ChinaUnicomCard;
-    } elseif (preg_match('/^(?:133|149|153|177|173|18[019]|19[0139])\d{8}$/', $cardno, $matches)) {
+    } elseif (preg_match('/^(?:133|153|177|173|18[019]|19[0139])\d{8}$/', $cardno, $matches)) {
+        return ChinaTelecomCard;
+    } elseif (preg_match('/^(1349)\d{7}$/', $cardno, $matches)) {
         return ChinaTelecomCard;
     } elseif (preg_match('/^1\d{10}$/', $cardno, $matches)) {
         return PhoneCard;
@@ -214,13 +251,19 @@ function card_type($cardno,&$regin_no)
     elseif(preg_match('/^1\d{10}$/',$cardno,$matches))
     {
         $regin_no = -1;
-        if (preg_match('/^134[0-8]\d{7}$|^(?:13[5-9]|147|15[0-27-9]|17[28]|18[2-478]|19[578])\d{8}$/', $cardno, $matches)) {
+        if (preg_match('/^134[0-8]\d{7}$|^(?:13[5-9]|15[012789]|17[28]|18[23478]|19[578])\d{8}$/', $cardno, $matches)) {
             return ChinaMobileCard;
-        } elseif (preg_match('/^(?:13[0-2]|145|15[56]|166|17[156]|18[56]|196)\d{8}$/', $cardno, $matches)) {
+        }
+        elseif (preg_match('/^(?:13[0-2]|15[56]|166|17[156]|18[56]|196)\d{8}$/', $cardno, $matches)) {
             return ChinaUnicomCard;
-        } elseif (preg_match('/^(?:133|149|153|177|173|18[019]|19[0139])\d{8}$/', $cardno, $matches)) {
+        }
+        elseif (preg_match('/^(?:133|153|177|173|18[019]|19[0139])\d{8}$/', $cardno, $matches)) {
+            return ChinaTelecomCard;
+        }
+        elseif (preg_match('/^(1349)\d{7}$/', $cardno, $matches)) {
             return ChinaTelecomCard;
-        } else {
+        }
+        else {
             return UnknownCard;
         }
     }
@@ -242,241 +285,6 @@ function oil_type($cardno)
     }
 }
 
-//[$validate,$card_type,$region_no,$isTransfer,$status,$black]
-function valid_phone($card_no)
-{
-    $type_checker = function ($channel)
-    {
-        if($channel == '联通') {
-            return ChinaUnicomCard;
-        }
-        elseif($channel == '电信') {
-            return ChinaTelecomCard;
-        }
-        elseif($channel == '移动') {
-            return ChinaMobileCard;
-        }
-        else {
-            return UnknownCard;
-        }
-    };
-
-    $validate_checker = function ($status)
-    {
-        // "status": 1 //状态 0:空号;1:实号;2:停机;3:库无;4:沉默号;5:风险号
-        Log::record("status={$status}",Log::DEBUG);
-        if (in_array($status, [0,5])) {
-            return false;
-        } else {
-            return true;
-        }
-    };
-
-    $regin_checker = function ($area)
-    {
-        if(empty($area)) return -1;
-        $areas = explode('-',$area);
-        if(count($areas) > 0)
-        {
-            $province = $areas[0];
-            $endtxts= ["省","市","自治区","特别行政区"];
-
-            foreach ($endtxts as $endtxt)
-            {
-                if(strpos($province, $endtxt) === false) {
-                    continue;
-                } else {
-                    $province = mb_strcut($province, 0, strrpos($province, $endtxt));
-                }
-            }
-
-            $region = array_search($province, ProvinceList);
-            return $region;
-        }
-        else {
-            return -1;
-        }
-    };
-
-    $ali = function ($card_no, &$validate, &$region_no,&$status) use ($validate_checker, $regin_checker): bool
-    {
-        $url = 'https://mobileempty.shumaidata.com/mobileempty';
-        $params['mobile'] = $card_no;
-        $headers = ["Authorization:APPCODE " . '8f92d951293f4d2ea48ff86d5a70c537'];
-
-        $net_err = 0;
-        $resp = http_request($url, $params, 'GET', false, $headers,$net_err);
-        if ($resp == false) return false;
-
-        $resp = json_decode($resp, true);
-        if ($resp == false) return false;
-
-        if ($resp['code'] == 200)
-        {
-            $data = $resp['data'];
-            $status = intval($data['status']);
-            $validate = $validate_checker(intval($data['status']));
-            $region_no = $regin_checker($data['area']);
-            return true;
-        } else {
-            Log::record("ali_valid phone:{$card_no} return msg:{$resp['msg']}", Log::DEBUG);
-            return false;
-        }
-    };
-
-    $tianyan = function ($card_no, &$validate, &$region_no,&$status) use ($validate_checker, $regin_checker): bool
-    {
-        $url = 'https://api.shumaidata.com/v4/mobile_empty/check';
-        $appid = '2Xfa6IFIPv0sVUjy';
-        $appSecurity = '2Xfa6IFIPv0sVUjynOddsfh6KXfbyJ84';
-        $cur = microtime (true);
-
-        $data['appid'] = $appid;
-        $data['timestamp'] = intval($cur * 1000);
-        $content = "{$appid}&{$data['timestamp']}&{$appSecurity}";
-        $data['sign'] = md5($content);
-        $data['mobile'] = $card_no;
-
-        $net_err = 0;
-        $resp = http_request($url, $data, 'GET',false, [],$net_err);
-        if ($resp == false) return false;
-
-        $resp = json_decode($resp, true);
-        if ($resp == false) return false;
-
-        if ($resp['code'] == 200)
-        {
-            $data = $resp['data'];
-            $status = intval($data['status']);
-            $validate = $validate_checker(intval($data['status']));
-            $region_no = $regin_checker($data['area']);
-            return true;
-        } else {
-            Log::record("tianyan_valid phone:{$card_no} return msg:{$resp['msg']}", Log::DEBUG);
-            return false;
-        }
-    };
-
-    $tianyan_cardtyper = function ($card_no) use ($type_checker)
-    {
-        $url = 'https://api.shumaidata.com/v4/mobile-transfer/query';
-        $appid = '2Xfa6IFIPv0sVUjy';
-        $appSecurity = '2Xfa6IFIPv0sVUjynOddsfh6KXfbyJ84';
-        $cur = microtime (true);
-
-        $data['appid'] = $appid;
-        $data['timestamp'] = intval($cur * 1000);
-        $content = "{$appid}&{$data['timestamp']}&{$appSecurity}";
-        $data['sign'] = md5($content);
-        $data['mobile'] = $card_no;
-
-        $net_err = 0;
-        $resp = http_request($url, $data, 'GET',false, [],$net_err);
-        if ($resp == false) return [false,UnknownCard,UnknownCard,false];
-
-        $resp = json_decode($resp, true);
-        if ($resp == false) return [false,UnknownCard,UnknownCard,false];
-
-        if ($resp['code'] == 200)
-        {
-            $data = $resp['data'];
-            $ispType = $data['ispType'];
-            $newIspType = $data['newIspType'];
-            Log::record("tianyan_transfer phone:{$card_no} ispType:{$ispType} newIspType:{$newIspType}", Log::DEBUG);
-
-            $card_type = $type_checker($newIspType);
-            $org_type = $type_checker($ispType);
-            $isTransfer = $org_type != $card_type;
-
-
-            return [true,$card_type,$org_type,$isTransfer];
-        } else {
-            Log::record("tianyan_transfer phone:{$card_no} return msg:{$resp['msg']}", Log::DEBUG);
-            return [false,UnknownCard,UnknownCard,false];
-        }
-    };
-
-    $time_checker = function ($update_time)
-    {
-        //90 天以内数据有效
-        $delta = time() - intval($update_time);
-        return $delta < 360 * 86400 && $delta >= 0;
-    };
-
-    $pinfo_getter = function ($card_no) use ($validate_checker,$time_checker)
-    {
-        $mod_card = Model('card_info');
-        $info = $mod_card->getCardInfo($card_no);
-
-        if(empty($info)) {
-            return [false,[]];
-        }
-        elseif($time_checker($info['update_time'])) {
-            $mod_card->where(['card_no' => $card_no])->update(['using_times' => $info['using_times'] + 1]);
-
-            $card_type = intval($info['card_type']);
-            $region_no = intval($info['regin']);
-            $isTransfer = intval($info['transfer']) == 0 ? false : true;
-            $status = intval($info['card_state']);
-            $black = intval($info['black']);
-            $validate = $validate_checker($status);
-
-            $result = [$validate,$card_type,$region_no,$isTransfer,$status,$black];
-            return [true,$result];
-        }
-        else {
-            return [false,[]];
-        }
-    };
-
-    $pinfo_updator = function ($card_no,$card_type,$org_type,$region_no,$isTransfer,$status)
-    {
-        $mod_card = Model('card_info');
-        $transfer = $isTransfer == true ? 1 : 0;
-        $mod_card->replace_card($card_no,$card_type,$org_type,$region_no,$transfer,$status);
-    };
-
-    $validate = true;
-    $black = 0;
-
-    $card_type = card_type($card_no,$region_no);
-    $region_no = -1;
-
-    if($card_type == PetroChinaCard || $card_type == SinopecCard) {
-        return [$validate,$card_type,$region_no,false,1,$black];
-    }
-
-    [$succ,$result] = $pinfo_getter($card_no);
-    if($succ) return $result;
-
-    [$succ,$_card_type,$_org_type,$_isTransfer] = $tianyan_cardtyper($card_no);
-    if($succ) {
-        $card_type = $_card_type;
-        $org_type = $_org_type;
-        $isTransfer = $_isTransfer;
-    }
-    else {
-        $isTransfer = false;
-    }
-
-    $status = 6;
-    $ret = $tianyan($card_no,$validate,$region_no,$status);
-    if($ret)
-    {
-        if($succ) $pinfo_updator($card_no,$card_type,$org_type,$region_no,$isTransfer,$status);
-        return [$validate,$card_type,$region_no,$isTransfer,$status,$black];
-    }
-
-    $ret = $ali($card_no,$validate,$region_no,$status);
-    if($ret)
-    {
-        if($succ) $pinfo_updator($card_no,$card_type,$org_type,$region_no,$isTransfer,$status);
-        return [$validate,$card_type,$region_no,$isTransfer,$status,$black];
-    }
-
-    return [true,$card_type,-1,false,$status,$black];
-}
-
 function is_validate($status)
 {
     if (in_array($status, [0,5])) {
@@ -486,104 +294,8 @@ function is_validate($status)
     }
 }
 
-
-function tencent_valid_phone($card_no)
+function valid_phone($card_no)
 {
-    $type_checker = function ($channel)
-    {
-        if($channel == 'CUCC') {
-            return ChinaUnicomCard;
-        }
-        elseif($channel == 'CTCC') {
-            return ChinaTelecomCard;
-        }
-        elseif($channel == 'CMCC') {
-            return ChinaMobileCard;
-        }
-        else {
-            return UnknownCard;
-        }
-    };
-
-    $validate_checker = function ($code)
-    {
-        // 字段code:【1 为实号;2为空号;3为停机;4为流量卡;5为沉默号】
-        Log::record("status={$code}",Log::DEBUG);
-        if (in_array($code, [2])) {
-            return false;
-        } else {
-            return true;
-        }
-    };
-
-    $regin_checker = function ($province)
-    {
-        if(empty($province)) return -1;
-        $endtxts= ["省","市","自治区","特别行政区"];
-
-        foreach ($endtxts as $endtxt)
-        {
-            if(strpos($province, $endtxt) === false) {
-                continue;
-            } else {
-                $province = mb_strcut($province, 0, strrpos($province, $endtxt));
-            }
-        }
-
-        return array_search($province, ProvinceList);
-    };
-
-    $api_function = function ($card_no, &$card_type, &$validate, &$region_no,&$status) use($type_checker, $validate_checker, $regin_checker)
-    {
-        $secretId = 'AKIDkd6sT6C4765LtYN1W2fN2WC2Ynr42acemjQW';
-        $secretKey = 'dupQeU838dhuQ8uDP2bi81nQNb5wt9KW1qLP7eWu';
-        $source = 'market';
-
-        // 签名
-        $datetime = gmdate('D, d M Y H:i:s T');
-        $signStr = sprintf("x-date: %s\nx-source: %s", $datetime, $source);
-        $sign = base64_encode(hash_hmac('sha1', $signStr, $secretKey, true));
-        $auth = sprintf('hmac id="%s", algorithm="hmac-sha1", headers="x-date x-source", signature="%s"', $secretId, $sign);
-        $header = [
-            "X-Source: {$source}",
-            "X-Date: {$datetime}",
-            "Authorization: {$auth}",
-        ];
-        $data['number'] = $card_no;
-        $url = 'https://service-empgc6lp-1256724964.sh.apigw.tencentcs.com/release/query';
-        $net_err = 0;
-        $resp = http_request($url, $data, 'GET',false, $header,$net_err);
-
-        if ($resp == false) return false;
-
-        $resp = json_decode($resp, true);
-        if ($resp == false) return false;
-
-        if ($resp['ret'] == 200)
-        {
-            $data = $resp['data'];
-            $code = intval($data['code']);
-            $extend = $data['extend'];
-            $status = $code;
-            $card_type = $type_checker($extend['isp']);
-            $validate = $validate_checker($code);
-            $region_no = $regin_checker($extend['prov']);
-            return true;
-        } else {
-            Log::record("tencent_valid phone:{$card_no}", Log::DEBUG);
-            return false;
-        }
-    };
-
-    $validate = true;
-    $card_type = card_type($card_no,$region_no);
-    $region_no = -1;
-    $status = 6;
-
-    $ret = $api_function($card_no, $card_type, $validate, $region_no, $status);
-    if($ret)
-    {
-        return [$validate,$card_type,$region_no,$status];
-    }
-    return [$validate,$card_type,-1,$status];
+    $query = new card_query();
+    return $query->validate($card_no);
 }

+ 6 - 2
helper/refill/RefillBase.php

@@ -295,7 +295,8 @@ class RefillBase
 
         $refill_state = false;
         $order_success = false;
-        $net_errno = 0;
+        $net_errno = '';
+        $neterr = false;
 
         foreach ($providers as $provider)
         {
@@ -387,7 +388,8 @@ class RefillBase
                 if(!is_string($errmsg)) {
                     $errmsg = "{$errmsg}";
                 }
-                $mod_refill->edit($order_id, ['commit_time' => time(),'err_msg' => $errmsg]);
+                $mod_refill->edit($order_id, ['commit_time' => time(), 'err_msg' => $errmsg]);
+//                $mod_refill->edit($order_id, ['commit_time' => time(), 'notify_time' => time(), 'err_msg' => $errmsg]);
             }
         }
 
@@ -396,7 +398,9 @@ class RefillBase
         } elseif ($order_success) {
             return [errcode::MERCHANT_REFILL_ERROR, "充值失败", $last_orderid, $neterr, $net_errno];
         } else {
+            //订单创建失败,不需要再重试了,可能已经是数据库等系统错误
             return [errcode::MERCHANT_REFILL_ERROR, "充值失败", $last_orderid, false, 0];
+//            return [errcode::MERCHANT_REFILL_ERROR, "充值失败", $last_orderid, false, 'ORDER_CREATE_FAIL'];
         }
     }
 

+ 3 - 2
helper/refill/api/xyz/shuoruan/RefillPhone.php

@@ -29,19 +29,20 @@ class RefillPhone extends refill\IRefillPhone
 
     public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
     {
-        $params_getter = function ($order_sn,$phone,$amount) {
+        $params_getter = function ($order_sn,$phone,$amount,$card_type) {
             $params = [];
             $params['orderId'] = $order_sn;
             $params['chargeAcct'] = $phone;
             $params['chargeCash'] = $amount;
             $params['chargeType'] = 0;
+            $params['ispName'] = urlencode(config::operator[$card_type]);
             $params['retUrl'] = urlencode(config::NOTIFY_URL);
             $params['action'] = 'CZ';
 
             return $params;
         };
 
-        $params = $params_getter($params['order_sn'], $card_no, $amount);
+        $params = $params_getter($params['order_sn'], $card_no, $amount, $card_type);
         $body = $this->pack_params($params);
 
         $resp = http_post_data(config::API_URL, $body, config::ExtHeaders, $net_errno);

+ 6 - 1
helper/refill/api/xyz/shuoruan/config.php

@@ -3,7 +3,7 @@
 
 namespace refill\shuoruan;
 
-
+use mtopcard;
 class config
 {
     const API_URL = 'http://api.sohan.hk:50080/API';
@@ -12,4 +12,9 @@ class config
     const KEY = '471D690CFB902BD8';
     const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_shuoruan.php";
     const ExtHeaders = ['Content-Type: application/json;charset=GB2312'];
+    const operator = [
+        mtopcard\ChinaMobileCard  => '移动',
+        mtopcard\ChinaUnicomCard  => '联通',
+        mtopcard\ChinaTelecomCard => '电信'
+    ];
 }

+ 5 - 1
helper/refill/api/xyz/yuanta/api.txt

@@ -10,4 +10,8 @@ appSecret:qXRRTTqrtAwwwtXp
 下单接口地址:http://59.110.225.82:8911/api/hf/order/submit
 查单接口地址:http://59.110.225.82:8911/api/order/query
 余额接口地址:http://59.110.225.82:8911/api/account/balance
-提卡接口地址:http://59.110.225.82:8911/api/card/get
+提卡接口地址:http://59.110.225.82:8911/api/card/get
+
+2022.3.14 增加电信商品编码
+100 面值    商品编码  100046
+200                 100047

+ 2 - 0
helper/refill/api/xyz/yuanta/config.php

@@ -21,6 +21,8 @@ class config
             200 => 100041
         ],
         mtopcard\ChinaTelecomCard => [
+            100 => 100046,
+            200 => 100047
         ],
     ];
     const ExtHeaders = ['Content-Type:application/x-www-form-urlencoded;charset=utf-8'];

+ 53 - 25
helper/refill/policy/mratio_control.php

@@ -318,7 +318,6 @@ class mratio_control
                 }
 
 //                Log::record("quality={$quality},card_type ={$card_type},spec={$spec}",Log::DEBUG);
-
                 $prices = $this->getPrice($mchid, $org_quality, $card_type, $spec);
                 $out_price = $prices[$org_quality];
                 $in_price = $prices[$quality] ?? false;
@@ -341,19 +340,8 @@ class mratio_control
             return $cur_pratio > $profit_ratio;
         };
 
-        $spec_max = function ($mchid,$qtsex, $org_quality, $qualities, $low_ratio,$period)
+        $spec_max = function ($mchid, $qtsex, $org_quality, $qualities, $low_ratio, $period)
         {
-            $specs = [];
-            $spec_qt = [];
-            foreach ($qtsex as $qts) {
-                [$quality, $card_type, $spec] = $qts;
-                $specs[] = $spec;
-                $spec_qt[$spec][] = [$quality,$card_type];
-            }
-
-            $specs = array_unique($specs);
-            sort($specs);
-
             $ratio_calc = function ($mchid, $specs, $spec_qt, $max_spec, $org_quality, $qualities, $period)
             {
                 $all_succ = 0;
@@ -363,9 +351,9 @@ class mratio_control
                 {
                     $qts = $spec_qt[$spec];
                     if($max_spec >= $spec) {
-                        $fHigtRatio = true;
+                        $fHighRatio = true; //此时采用面额中最高成功率计算
                     } else {
-                        $fHigtRatio = false;
+                        $fHighRatio = false;
                     }
 
                     $card_types = [];
@@ -380,13 +368,13 @@ class mratio_control
                     }
 
                     $detail_ratios = $this->detail_ratios($mchid, $qualities,$card_type, $spec, $period);
-                    if($fHigtRatio)
+                    if($fHighRatio)
                     {
                         $all = 0;
                         $ratios = [];
                         foreach ($detail_ratios as $quality => $sfr) {
                             [$succ,$fail,$ratio] = $sfr;
-//                            Log::record("high succ={$succ},fail={$fail},ratio = {$ratio}",Log::DEBUG);
+                            Log::record("high succ={$succ},fail={$fail},ratio = {$ratio}",Log::DEBUG);
                             $ratios[] = $ratio;
                             $all += $succ;
                             $all += $fail;
@@ -404,7 +392,7 @@ class mratio_control
                         foreach ($detail_ratios as $quality => $sfr)
                         {
                             [$succ,$fail,$ratio] = $sfr;
-//                            Log::record("normal succ={$succ},fail={$fail},ratio = {$ratio}",Log::DEBUG);
+                            Log::record("normal succ={$succ},fail={$fail},ratio = {$ratio}",Log::DEBUG);
                             $all_succ += $succ;
                             $all_fail += $fail;
                         }
@@ -415,11 +403,23 @@ class mratio_control
                 return round($ratio,4);
             };
 
+            ////////////////////////////////////////////////////////////////////////////////////////////////////////////
+            $specs = [];
+            $spec_qt = [];
+            foreach ($qtsex as $qts) {
+                [$quality, $card_type, $spec] = $qts;
+                $specs[] = $spec;
+                $spec_qt[$spec][] = [$quality,$card_type];
+            }
+
+            $specs = array_unique($specs);
+            sort($specs);
+
             for ($i = 0; $i < count($specs); $i++)
             {
                 $max_spec = $specs[$i];
                 $ratio = $ratio_calc($mchid, $specs, $spec_qt, $max_spec, $org_quality, $qualities, $period);
-//                Log::record("spec={$max_spec},ratio={$ratio},low_ratio={$low_ratio}",Log::DEBUG);
+                Log::record("spec={$max_spec},ratio={$ratio},low_ratio={$low_ratio}",Log::DEBUG);
                 if($ratio >= $low_ratio) {
                     break;
                 }
@@ -434,7 +434,7 @@ class mratio_control
         if($can_next)
         {
             $max_spec = $spec_max($mchid,$qtsex, $org_quality, $qualities, $low_ratio,$period);
-            Log::record("max_spec={$max_spec}",Log::DEBUG);
+            Log::record("mchid={$mchid} max_spec={$max_spec}",Log::DEBUG);
             if($max_spec >= $spec) {
                 return false;
             } else {
@@ -448,7 +448,24 @@ class mratio_control
 
     private function qts_checker($mchid, $org_quality,$cur_quality, $card_type, $spec, $qualities,$period,$header,$ratio)
     {
-        [$_succ, $_fail, $cur_ratio] = $this->detail_ratio($mchid, $cur_quality, $card_type, $spec, $period);
+        $ratio_calc = function ($mchid, $card_type, $spec, $period, $org_quality, $qualities)
+        {
+            $succs = 0;
+            $fails = 0;
+            foreach ($qualities as $quality)
+            {
+                if ($quality === $org_quality) continue;
+
+                [$_succ, $_fail, $cur_ratio] = $this->detail_ratio($mchid, $quality, $card_type, $spec, $period);
+                $succs += $_succ;
+                $fails += $_fail;
+            }
+            $ratio = round($succs / ($succs + $fails + 0.000001),4);
+
+            return $ratio;
+        };
+
+        $cur_ratio = $ratio_calc($mchid, $card_type, $spec, $period, $org_quality, $qualities);
         Log::record("{$header} cur_ratio = {$cur_ratio},lower_ratio={$ratio}",Log::DEBUG);
 
         if($cur_ratio >= $ratio) return true;
@@ -467,20 +484,31 @@ class mratio_control
 
             $profit = 0;
             $amount = 0;
+            $all_succs = 0;
             foreach ($qualities as $quality) {
                 $inprice = $prices[$quality] ?? false;
                 if ($inprice === false) continue;
 
                 [$succ, $fail, $ratio] = $dratios[$quality];
+                if($succ === 0) continue;
+
                 $profit += $succ * ($sale - $inprice);
                 $amount += $succ * $sale;
+                $all_succs += $succ;
             }
 
-            $cur_pratio = round(($profit + 0.00001) / ($amount + 0.00001),4);
-            $profit_ratio = round($profit_ratio,4);
+            if($all_succs === 0) {
+                Log::record("{$header} qts_checker all_succs = {$all_succs} can next quality",Log::DEBUG);
+                return true;
+            }
+            else
+            {
+                $cur_pratio = round($profit / ($amount + 0.000001),4);
+                $profit_ratio = round($profit_ratio,4);
 
-            Log::record("{$header} qts_checker cur_pratio = {$cur_pratio},profit_ratio={$profit_ratio}",Log::DEBUG);
-            return $cur_pratio > $profit_ratio;
+                Log::record("{$header} qts_checker cur_pratio = {$cur_pratio},profit_ratio={$profit_ratio}",Log::DEBUG);
+                return $cur_pratio > $profit_ratio;
+            }
         };
 
         $can_next = $profit_judger($org_quality,$qualities,$prices,$dratios,$profit_ratio);

+ 4 - 1
helper/refill/policy/quaility.php

@@ -286,14 +286,17 @@ class Quality
                     if($qsecs == false) continue;
 
                     if($left_time - $qsecs > 0) {
+                        //时间满足该质量配置
                         $left_time -= $qsecs;
                         $result[] = $quality;
                     }
                     elseif($left_time - $per_secs > 0) {
-                        $left_time -= $per_secs;
+                        //时间够跑一次,不能再找其它质量
                         $result[] = $quality;
+                        break;
                     }
                     else {
+                        //时间完全不够跑一次
                         break;
                     }
 

+ 4 - 0
helper/refill/util.php

@@ -609,6 +609,10 @@ class util
         }
     }
 
+    public static function order_errflag($net_errno) {
+        return ($net_errno === 'ORDER_CREATE_FAIL');
+    }
+
     public static function onOrderSuccess($refill_info,$order_info)
     {
         $data = store_member::instance()->get_member($order_info['store_id']);

+ 2 - 1
rdispatcher/proxy.php

@@ -42,7 +42,7 @@ class proxy
             refill\util::push_queue_order($mchid,$mch_order,ORDER_STATE_SEND);
             $refill_order->edit_detail($mchid,$mch_order,['order_state' => ORDER_STATE_SEND]);
         }
-        Log::record("proxy::add times={$order->commit_times()} mch_order={$mch_order} card_no = {$order->card_no()} regin_no={$order->region_no()} org_quality={$org_quality} quality={$quality}",Log::DEBUG);
+        Log::record("proxy::add times={$order->commit_times()} mch_order={$mch_order} card_no = {$order->card_no()} regin_no={$order->region_no()} org_quality={$order->org_quality()} quality={$order->cur_quality()}",Log::DEBUG);
 
         if ($this->canceled($mchid, $mch_order)) {
             return $this->onEerror($order, '订单被拦截');
@@ -76,6 +76,7 @@ class proxy
                 $fError = false;
             }
             elseif(($errcode === refill\errcode::MERCHANT_REFILL_ERROR && $neterr))
+//            elseif(($errcode === refill\errcode::MERCHANT_REFILL_ERROR) && refill\util::order_errflag($net_errno) === false)
             {
                 [$org_quality,$quality] = refill\RefillFactory::instance()->find_quality($order,true);
                 $order->set_quality($org_quality,$quality);

Fichier diff supprimé car celui-ci est trop grand
+ 7 - 0
test/TestBigData.php


+ 19 - 2
test/TestCardNo.php

@@ -66,7 +66,24 @@ class TestCardNo extends TestCase
 
     public function testTencentValidPhone()
     {
-        $card_no = 17801048874;
-        [$validate,$card_type,$region_no,$status] = mtopcard\tencent_valid_phone($card_no);
+//        $card_no = 13911129867;
+////        [$validate,$card_type,$region_no,$status] = mtopcard\tencent_valid_phone($card_no);
+//        [$validate, $card_type, $regin_no, $isTransfer, $card_state, $black] = mtopcard\valid_phone($card_no);
+
+        $card_nos = [15970039005];
+        foreach ($card_nos as $card_no)
+        {
+            [$validate, $card_type, $regin_no, $isTransfer, $card_state, $black] = mtopcard\valid_phone($card_no);
+
+            $transfer = $isTransfer ? 1 : 0;
+            Log::record("{$card_no} transfer={$transfer}",Log::DEBUG);
+        }
+    }
+
+    public function testCardType()
+    {
+        $card_no = 15970039005;
+        $card_type = mtopcard\card_type($card_no,$region);
+
     }
 }

+ 6 - 0
test/TestRedis.php

@@ -353,6 +353,12 @@ class TestRedis extends TestCase
 
     }
 
+    public function testErrorFlag()
+    {
+        $flag1 = refill\util::order_errflag(0);
+        $flag2 = refill\util::order_errflag('ORDER_CREATE_FAIL');
+    }
+
     ////docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRedis::testCancel)( .*)?$/" --test-suffix TestRedis.php /var/www/html/test
     ////docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRedis::testCancelPayed)( .*)?$/" --test-suffix TestRedis.php /var/www/html/test
     public static function tearDownAfterClass() : void

+ 1 - 1
test/TestRefill.php

@@ -1215,7 +1215,7 @@ class TestRefill extends TestCase
     {
         $provider = $this->getProvider('shuoruan');
 //        $resp = $provider->balance();
-        $resp = $provider->add(13699279618, 4, 10, ['order_sn' => $this->make_sn()]);
+        $resp = $provider->add(13911129867, 5, 10, ['order_sn' => $this->make_sn()]);
 //        $resp = $provider->query(['order_sn' => '80261634802627091026']);
 
         $params['Action'] = 'CX';

+ 7 - 0
util/shtest/var.sh

@@ -0,0 +1,7 @@
+#!/bin/bash
+
+
+slave_hosts=$XYZ_SLAVE_HOSTS
+echo $slave_hosts
+
+vdb=$(df -h | grep /dev/vdb1 | awk 'BEGIN{OFS=","}{print $1,$2,$3,$4}')