Example #1
0
 public function actionOpenidBindMobilesWithLocation()
 {
     header('content-type:text/html;charset=utf-8');
     $appkey = '5d4a589b32d70ad6378c8c69cba63524';
     #通过聚合申请到数据的appkey
     $url = 'http://apis.juhe.cn/mobile/get';
     #请求的数据接口URL
     $total_count = \app\models\OpenidBindMobile::find()->count();
     $step = 3000;
     $start = 0;
     $n = 0;
     while ($start < $total_count) {
         //$fans = \app\models\MUser::find()->offset($start)->limit($step)->all();
         $openidBindMobiles = \app\models\OpenidBindMobile::find()->offset($start)->limit($step)->orderBy(['create_time' => SORT_ASC])->all();
         foreach ($openidBindMobiles as $mobile) {
             //$n = $n + 1;
             //微信昵称  绑定手机号   关注时间
             $user = \app\models\MUser::findOne(['openid' => $mobile->openid]);
             if (empty($user)) {
                 printf(\yii\helpers\Json::encode($mobile));
                 continue;
             } else {
                 $office = \app\models\MOffice::findOne(['office_id' => $user->belongto]);
             }
             if (empty($mobile->carrier)) {
                 $params = 'phone=' . $mobile->mobile . '&key=' . $appkey;
                 $content = \app\commands\ExportController::juhecurl($url, $params, 0);
                 if ($content) {
                     $result = json_decode($content, true);
                     #print_r($result);
                     #错误码判断
                     $error_code = $result['error_code'];
                     if ($error_code == 0) {
                         #根据所需读取相应数据
                         $data = $result['result'];
                         //echo '结果为:'.$data['area'].' '.$data['location'];
                         $province = $data['province'];
                         $city = $data['city'];
                         $areacode = $data['areacode'];
                         $zip = $data['zip'];
                         $company = $data['company'];
                         $card = $data['card'];
                     } else {
                         //echo $error_code.':'.$result['reason'];
                         $province = '--';
                         $city = '--';
                         $areacode = '--';
                         $zip = '--';
                         $company = '--';
                         $card = '--';
                     }
                 }
                 $mobile->carrier = $data['company'];
                 $mobile->province = $data['province'];
                 $mobile->city = $data['city'];
                 $mobile->areacode = $data['areacode'];
                 $mobile->zip = $data['zip'];
                 $mobile->cardtype = $data['card'];
                 $mobile->save(false);
             }
             //if($n > 10) break;
         }
         $start += $step;
     }
 }
Example #2
0
File: U.php Project: noikiy/wowewe
 public static function getMobileLocation($mobile)
 {
     /*
             $method = 'GET';
             $format = 'json';
             $url = 'http://v.showji.com/Locating/showji.com20150416273007.aspx';
             $params['m'] = $mobile;
             $params['output'] = $format;
             try {
                 $requestUrl = $url . '?';
                 if ($method == 'GET') {
                     $requestUrl .= http_build_query($params);
                     $postFields = null;                
                 } else {
                     $postFields = $params;
                 }            
                 $resp = U::curl($requestUrl, $postFields);    
             } catch (Exception $e) {
                 U::W($e->getCode().':'.$e->getMessage());
                 return ['errcode'=>$e->getCode(), 'errmsg'=>$e->getMessage()];
             }
     
             if ("json" === $format) {
                 $arr = json_decode($resp, true);
                 if (null !== $arr)
                     return $arr;
             } else if("xml" === $format) {
                 $respObject = @simplexml_load_string($resp);
                 if (false !== $respObject) {
                     return json_decode(json_encode($respObject), true);            
                 }
             }
             return ['errcode'=>90000, 'errmsg'=>'HTTP_RESPONSE_NOT_WELL_FORMED'];     
     */
     header('content-type:text/html;charset=utf-8');
     $appkey = '5d4a589b32d70ad6378c8c69cba63524';
     #通过聚合申请到数据的appkey
     $url = 'http://apis.juhe.cn/mobile/get';
     #请求的数据接口URL
     $params = 'phone=' . $mobile . '&key=' . $appkey;
     $content = \app\commands\ExportController::juhecurl($url, $params, 0);
     if ($content) {
         $result = json_decode($content, true);
         $resp = $result['result'];
         if ($result['error_code'] == 0) {
             return $resp;
         }
     }
     return ['errcode' => 90000, 'errmsg' => 'HTTP_RESPONSE_NOT_WELL_FORMED'];
 }