Heim  >  Artikel  >  php教程  >  微店自动发货助手源码

微店自动发货助手源码

WBOY
WBOYOriginal
2016-06-20 08:42:445129Durchsuche

通过微店开放平台自主型应用的订单消息推送功能,实现了微店虚拟商品自动发货。
消费url 形如:http://wd.17train.com/index.php/Admin/Index/api/uid/3
public function api(){<br>         $get = implode("-",$_GET);<br>         $getinfo = explode("-",$get);<br>         <br>         if (!file_exists('Public/Data/'.$getinfo[0])){ <br>             mkdir ('Public/Data/'.$getinfo[0]);<br>         }<br>         if(!empty($_POST)){<br>             file_put_contents('Public/Data/'.$getinfo[0].'/'.$getinfo[1].'.txt',$_POST);<br>             <br>             $this->json_jx($getinfo[1],$getinfo[0]);<br>         }<br>     }<br>     <br>     public function json_jx($filename,$uid){<br>         <br>          $str = file_get_contents("http://".$_SERVER['SERVER_NAME']."/Public/Data/".$uid."/".$filename.".txt");<br>          $str = str_replace('{"x_forwarded_for":null}',"",$str);<br>          $json = json_decode($str,true);<br>         if($json['type'] == 'weidian.order.already_payment'){<br>             if(empty($json['message']['send_time'])){ $time = time();}else{ $time = $json['message']['send_time'];}<br>             if(empty($json['message']['pay_time'])){ $time2 = time();}else{ $time2 = $json['message']['pay_time'];}<br>             $arr = array(<br>                 'order_id'=>$json['message']['order_id'],<br>                 'buyer_note'=>$json['message']['note'],<br>                 'item_id'=>$json['message']['items'][0]['item_id'],<br>                 'sku_id'=>$json['message']['items'][0]['sku_id'],<br>                 'uid'=>$uid,<br>                 'time'=>$time,<br>                 'order_time'=>$time2,<br>                 'status'=>$json['message']['status']<br>             );<br>             $res = M('order')->add($arr);<br>             $grinfo = M('mail')->where('uid = '.$uid)->find();<br>             if($grinfo['type'] == 1){<br>                 $conf = array(<br>                     'MAIL_HOST' =>$grinfo['smtp'],//smtp服务器的名称<br>                     'MAIL_SMTPAUTH' =>TRUE, //启用smtp认证<br>                     'MAIL_USERNAME' =>$grinfo['username'],//你的邮箱名<br>                     'MAIL_FROM' =>$grinfo['username'],//发件人地址<br>                     'MAIL_FROMNAME'=>'微店自动发货助手',//发件人姓名<br>                     'MAIL_PASSWORD' =>$grinfo['password'],//邮箱密码<br>                     'MAIL_CHARSET' =>'utf-8',//设置邮件编码<br>                     'MAIL_ISHTML' =>TRUE, // 是否HTML格式邮件<br>                 );<br>             }else{<br>                 $conf = array(<br>                     'MAIL_HOST' =>'smtp.163.com',//smtp服务器的名称<br>                     'MAIL_SMTPAUTH' =>TRUE, //启用smtp认证<br>                     'MAIL_USERNAME' =>'weidianzhushou@163.com',//你的邮箱名<br>                     'MAIL_FROM' =>'weidianzhushou@163.com',//发件人地址<br>                     'MAIL_FROMNAME'=>'微店自动发货助手',//发件人姓名<br>                     'MAIL_PASSWORD' =>'xxxxxxxxxx',//邮箱密码<br>                     'MAIL_CHARSET' =>'utf-8',//设置邮件编码<br>                     'MAIL_ISHTML' =>TRUE, // 是否HTML格式邮件<br>                 );<br>             }<br>             $mail = M('send')->where("sku_id = '".$arr['sku_id']."'")->find();<br>             $mail2 = M('send_kami')->where("`sku_id` = ".$arr['sku_id']." and `isuse` = 0 ")->find();<br>             if($mail['type'] == 0){<br>                 $title = $mail['title'];<br>                 $content = $mail['content'];<br>             }else{<br>                 $title = $mail['title'];<br>                 $content = $mail2['kahao']."--".$mail2['mima'];<br>             }<br>             <br>             $srs = SendMail($arr['buyer_note'],$title,$content,$conf);<br>             if($mail['type'] == 1){<br>                 $ww = array(<br>                     'isuse'=>1<br>                 );<br>                 M('send_kami')->where('id = '.$mail2['id'])->save($ww);<br>             }<br>             <br>             $ress = M('user')->where('id = '.$uid)->find();<br>             if($ress['sctime'] != date('Ymd')){<br>                 $this->aksc($uid);<br>                 $ress = M('user')->where('id = '.$uid)->find();<br>             }<br>             <br>             $ak = $ress['ak'];<br>             $urll = "http://api.vdian.com/api?param={\"order_id\":\"{$arr['order_id']}\",\"express_type\":\"999\",\"express_no\":\"1234566788\"}&public={\"method\":\"vdian.order.deliver\",\"access_token\":\"{$ak}\",\"version\":\"1.0\",\"format\":\"json\"}";<br>             $ra = https_request($urll,$ra);<br>             $results = json_decode($ra,true);<br>             $crr = array(<br>                 'isfh'=>1<br>             );<br>             M('order')->where('order_id = '.$arr['order_id'])->save($crr);<br>         }<br>          <br>         <br>     }<br>     <br>     public function wdfh($uid,$order_id){<br>         $where['id'] = $uid;<br>         $res = M('user')->where($where)->find();<br>         if($res['sctime'] != date('Ymd')){<br>             $this->aksc($where['id']);<br>         }<br>         <br>         $ra = https_request($urls,$ra);<br>         $results = json_decode($ra,true);<br>         if($results['status']['status_reason'] == 'success'){<br>             $w['status'] = 'send';<br>             M('order')->where("order_id = '".$order_id."'")->save($w);<br>         }<br>     }<br>     <br>     public function aksc($uid){<br>         $where['id'] = $uid;<br>         $res = M('user')->where($where)->find();<br>         $url = "https://api.vdian.com/token?grant_type=client_credential&appkey=".$res['appkey']."&secret=".$res['secret'];<br>         <br>         $r = https_request($url,$r);<br>         $akarr = json_decode($r,true);<br>         if(!empty($akarr)){<br>             $aa = array(<br>                 'ak'=>$akarr['result']['access_token'],<br>                 'sctime'=>date('Ymd')<br>             );<br>             $rr = M('user')->where("id = ".$uid)->save($aa);<br>             return $rr;<br>         }<br>     }函数/**<br>  * 邮件发送函数<br>  */<br>     function sendMail($to, $title, $content,$conf) {<br>      <br>         Vendor('PHPMailer.PHPMailerAutoload');     <br>         $mail = new PHPMailer(); //实例化<br>         $mail->IsSMTP(); // 启用SMTP<br>         $mail->Host=$conf['MAIL_HOST']; //smtp服务器的名称(这里以QQ邮箱为例)<br>         $mail->SMTPAuth = $conf['MAIL_SMTPAUTH']; //启用smtp认证<br>         $mail->Username = $conf['MAIL_USERNAME']; //你的邮箱名<br>         $mail->Password = $conf['MAIL_PASSWORD'] ; //邮箱密码<br>         $mail->From = $conf['MAIL_FROM']; //发件人地址(也就是你的邮箱地址)<br>         $mail->FromName = $conf['MAIL_FROMNAME']; //发件人姓名<br>         $mail->AddAddress($to,"尊敬的客户");<br>         $mail->WordWrap = 50; //设置每行字符长度<br>         $mail->IsHTML($conf['MAIL_ISHTML']); // 是否HTML格式邮件<br>         $mail->CharSet=$conf['MAIL_CHARSET']; //设置邮件编码<br>         $mail->Subject =$title; //邮件主题<br>         $mail->Body = $content; //邮件内容<br>         $mail->AltBody = "这是一个纯文本的身体在非营利的HTML电子邮件客户端"; //邮件正文不支持HTML的备用显示<br>         return($mail->Send());<br>     }<br>     <br>     <br>     function https_request($url, $data = null)<br>     {<br>         $curl = curl_init();<br>         curl_setopt($curl, CURLOPT_URL, $url);<br>         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);<br>         curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);<br>         if (!empty($data)){<br>             curl_setopt($curl, CURLOPT_POST, 1);<br>             curl_setopt($curl, CURLOPT_POSTFIELDS, $data);<br>         }<br>         curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);<br>         $output = curl_exec($curl);<br>         curl_close($curl);<br>         return $output;<br>     }<br>     表结构
微店自动发货助手源码
微店自动发货助手源码
微店自动发货助手源码
微店自动发货助手源码

附件是数据库结构

附件 weidian.zip ( 1.88 KB 下载:0 次 )

AD:真正免费,域名+虚机+企业邮箱=0元

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn