欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

微店自动发货助手源码

程序员文章站 2024-02-04 09:03:28
...
通过微店开放平台自主型应用的订单消息推送功能,实现了微店虚拟商品自动发货。
消费url 形如:http://wd.17train.com/index.php/Admin/Index/api/uid/3
public function api(){
$get = implode("-",$_GET);
$getinfo = explode("-",$get);

if (!file_exists('Public/Data/'.$getinfo[0])){
mkdir ('Public/Data/'.$getinfo[0]);
}
if(!empty($_POST)){
file_put_contents('Public/Data/'.$getinfo[0].'/'.$getinfo[1].'.txt',$_POST);

$this->json_jx($getinfo[1],$getinfo[0]);
}
}

public function json_jx($filename,$uid){

$str = file_get_contents("http://".$_SERVER['SERVER_NAME']."/Public/Data/".$uid."/".$filename.".txt");
$str = str_replace('{"x_forwarded_for":null}',"",$str);
$json = json_decode($str,true);
if($json['type'] == 'weidian.order.already_payment'){
if(empty($json['message']['send_time'])){ $time = time();}else{ $time = $json['message']['send_time'];}
if(empty($json['message']['pay_time'])){ $time2 = time();}else{ $time2 = $json['message']['pay_time'];}
$arr = array(
'order_id'=>$json['message']['order_id'],
'buyer_note'=>$json['message']['note'],
'item_id'=>$json['message']['items'][0]['item_id'],
'sku_id'=>$json['message']['items'][0]['sku_id'],
'uid'=>$uid,
'time'=>$time,
'order_time'=>$time2,
'status'=>$json['message']['status']
);
$res = M('order')->add($arr);
$grinfo = M('mail')->where('uid = '.$uid)->find();
if($grinfo['type'] == 1){
$conf = array(
'MAIL_HOST' =>$grinfo['smtp'],//smtp服务器的名称
'MAIL_SMTPAUTH' =>TRUE, //启用smtp认证
'MAIL_USERNAME' =>$grinfo['username'],//你的邮箱名
'MAIL_FROM' =>$grinfo['username'],//发件人地址
'MAIL_FROMNAME'=>'微店自动发货助手',//发件人姓名
'MAIL_PASSWORD' =>$grinfo['password'],//邮箱密码
'MAIL_CHARSET' =>'utf-8',//设置邮件编码
'MAIL_ISHTML' =>TRUE, // 是否HTML格式邮件
);
}else{
$conf = array(
'MAIL_HOST' =>'smtp.163.com',//smtp服务器的名称
'MAIL_SMTPAUTH' =>TRUE, //启用smtp认证
'MAIL_USERNAME' =>'weidianzhushou@163.com',//你的邮箱名
'MAIL_FROM' =>'weidianzhushou@163.com',//发件人地址
'MAIL_FROMNAME'=>'微店自动发货助手',//发件人姓名
'MAIL_PASSWORD' =>'xxxxxxxxxx',//邮箱密码
'MAIL_CHARSET' =>'utf-8',//设置邮件编码
'MAIL_ISHTML' =>TRUE, // 是否HTML格式邮件
);
}
$mail = M('send')->where("sku_id = '".$arr['sku_id']."'")->find();
$mail2 = M('send_kami')->where("`sku_id` = ".$arr['sku_id']." and `isuse` = 0 ")->find();
if($mail['type'] == 0){
$title = $mail['title'];
$content = $mail['content'];
}else{
$title = $mail['title'];
$content = $mail2['kahao']."--".$mail2['mima'];
}

$srs = SendMail($arr['buyer_note'],$title,$content,$conf);
if($mail['type'] == 1){
$ww = array(
'isuse'=>1
);
M('send_kami')->where('id = '.$mail2['id'])->save($ww);
}

$ress = M('user')->where('id = '.$uid)->find();
if($ress['sctime'] != date('Ymd')){
$this->aksc($uid);
$ress = M('user')->where('id = '.$uid)->find();
}

$ak = $ress['ak'];
$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\"}";
$ra = https_request($urll,$ra);
$results = json_decode($ra,true);
$crr = array(
'isfh'=>1
);
M('order')->where('order_id = '.$arr['order_id'])->save($crr);
}


}

public function wdfh($uid,$order_id){
$where['id'] = $uid;
$res = M('user')->where($where)->find();
if($res['sctime'] != date('Ymd')){
$this->aksc($where['id']);
}

$ra = https_request($urls,$ra);
$results = json_decode($ra,true);
if($results['status']['status_reason'] == 'success'){
$w['status'] = 'send';
M('order')->where("order_id = '".$order_id."'")->save($w);
}
}

public function aksc($uid){
$where['id'] = $uid;
$res = M('user')->where($where)->find();
$url = "https://api.vdian.com/token?grant_type=client_credential&appkey=".$res['appkey']."&secret=".$res['secret'];

$r = https_request($url,$r);
$akarr = json_decode($r,true);
if(!empty($akarr)){
$aa = array(
'ak'=>$akarr['result']['access_token'],
'sctime'=>date('Ymd')
);
$rr = M('user')->where("id = ".$uid)->save($aa);
return $rr;
}
}
函数/**
* 邮件发送函数
*/
function sendMail($to, $title, $content,$conf) {

Vendor('PHPMailer.PHPMailerAutoload');
$mail = new PHPMailer(); //实例化
$mail->IsSMTP(); // 启用SMTP
$mail->Host=$conf['MAIL_HOST']; //smtp服务器的名称(这里以QQ邮箱为例)
$mail->SMTPAuth = $conf['MAIL_SMTPAUTH']; //启用smtp认证
$mail->Username = $conf['MAIL_USERNAME']; //你的邮箱名
$mail->Password = $conf['MAIL_PASSWORD'] ; //邮箱密码
$mail->From = $conf['MAIL_FROM']; //发件人地址(也就是你的邮箱地址)
$mail->FromName = $conf['MAIL_FROMNAME']; //发件人姓名
$mail->AddAddress($to,"尊敬的客户");
$mail->WordWrap = 50; //设置每行字符长度
$mail->IsHTML($conf['MAIL_ISHTML']); // 是否HTML格式邮件
$mail->CharSet=$conf['MAIL_CHARSET']; //设置邮件编码
$mail->Subject =$title; //邮件主题
$mail->Body = $content; //邮件内容
$mail->AltBody = "这是一个纯文本的身体在非营利的HTML电子邮件客户端"; //邮件正文不支持HTML的备用显示
return($mail->Send());
}


function https_request($url, $data = null)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($data)){
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
表结构
微店自动发货助手源码
微店自动发货助手源码
微店自动发货助手源码
微店自动发货助手源码

附件是数据库结构

微店自动发货助手源码 weidian.zip ( 1.88 KB 下载:0 次 )

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