Exemplo n.º 1
0
 public function action_ajax_huizhe_update()
 {
     $configs = $this->getHuizheConfig();
     $transrNo = time() . mt_rand(10, 99);
     $usebase = $_POST['usebase'];
     if ($usebase == 1) {
         $transrNo = 'BASE' . $transrNo;
     }
     $md5Str = md5($configs['key'] . $configs['partnerid'] . $transrNo);
     $str = '<?xml version="1.0" encoding="utf-8"?>
     <ProductsQueryRequest><TransrNo>' . $transrNo . '</TransrNo>
     <MD5Str>' . $md5Str . '</MD5Str>
     <PartnerID>' . $configs['partnerid'] . '</PartnerID>
     <SonPartnerID>' . $configs['sonpartnerid'] . '</SonPartnerID>
     </ProductsQueryRequest>';
     $post = array('requestStr' => $str);
     $content = http_build_query($post);
     $content_length = strlen($content);
     $options = array('http' => array('method' => 'POST', 'header' => "Content-type: application/x-www-form-urlencoded\r\n" . "Content-length: {$content_length}\r\n", 'content' => $content));
     echo $str;
     $xml = file_get_contents("http://newcloud.hzins.com/WebAPI/HZ_Service.asmx/API_ProductsQuery", false, stream_context_create($options));
     echo $xml;
     //  var_dump($xml);
     if (!$xml) {
         echo json_encode(array('status' => false, 'msg' => '获取产品列表错误,请检查配置是否正确'));
         return;
     }
     $xmlArr = Common::xml_to_array($xml);
     if (empty($xmlArr['ProductsQuery']) || empty($xmlArr['ProductsQuery']['ProductQuery'])) {
         echo json_encode(array('status' => false, 'msg' => '获取产品列表错误,请检查配置是否正确'));
         return;
     }
     $products = $xmlArr['ProductsQuery']['ProductQuery'];
     foreach ($products as $k => $v) {
         unset($v['ProductDetailsResponse']['ProductDetails']['ProductUnderwriting']['CoverageAreas']);
         Model_Insurance::updateProduct('huizhe', $v);
     }
     echo json_encode(array('status' => true, 'msg' => '更新完成'));
 }