微信小店

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php


        include 'weixinjosn.php';
  
     
        //获取access_token的值
        function get_access_token($appid,$secret){
             $url_at='https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$secret;  
        $html = file_get_contents($url_at); 
      //  echo $html;
        $i = 0;
        $acces_token= (Array)json_decode($html);
        $access=array("","");                  
         foreach ($acces_token as $value) {
             $access[$i]=$value;              
                $i++;
                }
                session_start();
               $_SESSION['acces_token']=$access[0];             
                return $access[0];           
        }
   // echo get_access_token('wxf058dfd6a225a0e1', '64db401707a51f24dd6f4adee778b27f');
        
//  $url  = "http://api.weixin.qq.com/merchant/create?access_token=F5xLoXsXM2_oiNbZ669UdofJoQUlrkfGMyee_V-FJRXtvB6m_LyKtO51FCjzPINNbk4NfKostedVeSr9phoMxQ";


//$data_string ='[{"data":{"hello":"world"},"type":"1234","date":"2012-10-30 17:6:9","user":"000000000000000","time_stamp":1351587969902}, {"data":{"hello":"world"},"type":"1234","date":"2012-10-30 17:12:53","user":"000000000000000","time_stamp":1351588373519}]';
  
//$data_string= '[{"location": 1,"isPostFree": 0,"isHasReceipt": 1,"isUnderGuaranty": 0,"isSupportReplace": 0}]';


    $data_json = new weixinjosn();
    
    $data_json->category_id="12414";
   
  //  echo $data_json->date();
    //增加商品
   $data_josn_end = $data_json->adddate();
   $data = json_encode($data_josn_end); 


//echo $data;


 
list($return_code, $return_content) = http_post_data($url, $data_josn_end);


        
 function http_post_data($url, $data_string) {
    echo $data_string;
        $ch = curl_init();
        
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8',
'Content-Length: ' . strlen($data_string))
);       
        ob_start();
        $output= curl_exec($ch);   
        $return_content = ob_get_contents();
        ob_end_clean();
        $return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        echo $output; 
        return $output; 
  //      return array($return_code, $return_content);


    }
    //增加商品
    
     function  add_shangping(){
         $url  = "http://api.weixin.qq.com/merchant/create?access_token=F5xLoXsXM2_oiNbZ669UdofJoQUlrkfGMyee_V-FJRXtvB6m_LyKtO51FCjzPINNbk4NfKostedVeSr9phoMxQ";
         $data_josn_end = $data_json->adddate();
         $data = json_encode($data_josn_end); 
         http_post_data($url, $data_josn_end);
     }
    
    //删除商品
    function  del_shangping($product_id){
        $url="http://api.weixin.qq.com/merchant/del?access_token=ACCESS_TOKEN";
        $data_josn_del =$data_json->deldate($product_id);
        http_post_data($url, $data_josn_del);
    }
    
    //修改商品
    function  update_shangping(){
      $url="http://api.weixin.qq.com/merchant/update?access_token=ACCESS_TOKEN";
       $data_josn_update =$data_json->updatedate();
        http_post_data($url,$data_josn_update);
    }
    //查询商品
    function  select_shangping($product_id){
        $url="https://api.weixin.qq.com/merchant/get?access_token=ACCESS_TOKEN";
         $data_josn_select =$data_json->selectdate($product_id);
         http_post_data($url,$data_josn_select);        
    }
    //
    
        ?>
        
    </body>

</html>







<?php 
class  weixinjosn {
      public  $category_id='32472384';
      public  $id1='32423';
      public  $vid1='24234';
      public  $id2='234234';
      public  $vid2='32423';
      public  $id3='23423';
      public  $vid3='234234';
      public  $name='324324';   
      public  $sku_info_id='23423';
      public  $sku_info_vid='23423';
      public  $main_img='234';
      public  $img='234';
  
      public  $text='43223';
      public  $detail_img='23432';
      public  $detail_text='23423';
      public  $buy_limit='23423';
     
      public  $sku_id='234';
      public  $price=0;
      public  $icon_url='23432';
      public  $product_code='23432';
      public  $ori_price=0;
      public  $quantity=0;
      public  $sku_id1='23423';
      public  $price1=0;
      public  $icon_url1='23432';
      public  $product_code1='32423';
      public  $ori_price1=0;
      public  $quantity1=0;
      public  $country='中国',$province='广东',$city='珠海',$address='香宁一街';
      public  $isPostFree=0,$isHasReceipt=1,$isUnderGuaranty=0,$isSupportReplace=0;
      public  $delivery_type=0,$template_id=0;
      public  $express_PY_id='10000027',$express_PY_price=0,$express_KD_id='10000028',$express_KD_price=0,$express_ENS_id='10000029',$express_ENS_price=0;


    
      function  adddate (){
          
         $data_string= '{"product_base": {"category_id": ["'.$this->category_id.'"],"property": [{"id": "'.$this->id1.'","vid": '.$this->vid1.'},{"id": "'.$this->id2.'","vid": "'.$this->vid2.'"},{"id":"'.$this->id3.'","vid": "'.$this->vid3.'"}],
"name": "'.$this->name.'",
"sku_info": [
{
"id": "'.$this->sku_info_id.'",
"vid": [
"'.$this->sku_info_vid.'"
]
}
],
"main_img":"'.$this->main_img.'", 
"img": [
"'.$this->img.'"
],
"detail": [
{
"text": "'.$this->text.'"
},
{
"img":"'.$this->detail_img.'"
},
{
"text": "'.$this->detail_text.'"
}
],
"buy_limit": "'.$this->buy_limit.'"
},
"sku_list": [
{
"sku_id":" '.$this->sku_id.'",
"price": '.$this->price.',
"icon_url": "'.$this->icon_url.'",
"product_code,":"'.$this->product_code.'" ,
"ori_price,": '.$this->ori_price.',
"quantity": '.$this->quantity.'
},
{
"sku_id": "'.$this->sku_id1.'",
"price": '.$this->price1.',
"icon_url": "'.$this->icon_url1.'",
"product_code": "'.$this->product_code1.'",
"ori_price": '.$this->ori_price1.',
"quantity": '.$this->quantity1.'
}
],
"attrext": {
"location": {
"country": "'.$this->country.'",
"province": "'.$this->province.'",
"city": "'.$this->city.'",
"address": "'.$this->address.'"
},
"isPostFree": '.$this->isPostFree.',
"isHasReceipt": '.$this->isHasReceipt.',
"isUnderGuaranty": '.$this->isUnderGuaranty.',
"isSupportReplace": '.$this->isSupportReplace.'
},
"delivery_info": {
"delivery_type": '.$this->delivery_type.',
"template_id": '.$this->template_id.', 
"express": [
{
"id": "'.$this->express_PY_id.'", 
"price": '.$this->express_PY_price.'
}, 
{
"id": "'.$this->express_KD_id.'", 
"price": '.$this->express_KD_price.'
}, 
{
"id": "'.$this->express_ENS_id.'", 
"price": '.$this->express_ENS_price.'
}
]
}
}';
         return $data_string;
      }
      //删除商品
      function  deldate ($product_id){
          return '{"product_id":'.$product_id.'}';          
      }
      
      //修改商品
      function  updatedate(){
           adddate ();
      }
      function  selectdate($product_id){
          return '{"product_id":'.$product_id.'}';
          
      }
      
      }






 ?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值