public function test() { echo U('/zjh/game/detail', array('id' => 234), true, true); $data = \Wechat\Wxapi::dwz(U('/zjh/game/detail', array('id' => 234), true, true)); print_r($data); die; }
/** * 系统初始化 */ public function _initialize() { $this->user_id = session('user_id'); $this->user_id = 10004; // return true; $openid = session('openid'); if (!$openid) { $openid = cookie('openid'); if ($openid) { session('openid', $openid); } } // 系统获取当前用户 if (!$this->user_id) { if ($openid) { // 用户登录 $user = M('user')->where(array('openid' => $openid))->find(); if ($user) { session('subscribe', $user['subscribe']); session('user_id', $user['uin']); $this->user_id = $user['uin']; if ($user['wx_last_time'] < time() - 86400) { if ($user['subscribe']) { // 自动获取 $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; header("Location: " . U("/weixin/userinfo") . '?url=' . urlencode($url)); } else { // 网页授权 \Wechat\Wxapi::authorize(); exit; } } } else { \Wechat\Wxapi::authorize(); exit; } } else { // 网页授权 \Wechat\Wxapi::authorize(); exit; } } else { $user = M('user')->find($this->user_id); if ($user) { session('user_id', $user['uin']); // echo $user['subscribe'].'-'; session('subscribe', $user['subscribe']); } } $signPackage = \Wechat\Wxapi::getSignPackage(); $this->signPackage = $signPackage; $this->share_title = "凑红包, 有福利, 你懂得"; $this->share_link = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"; $this->share_imgUrl = "http://{$_SERVER['HTTP_HOST']}/images/logo.jpg"; $this->share_desc = "凑红包, 有福利, 你懂得."; $this->subscribe = session('subscribe'); // if(!$this->user_id) }
/** * @param $app * @param $param */ static function U($app, $param = array()) { $url = "http://sh.kakaapp.com/index.php?s=" . str_replace('__APP__', '', U($app, $param)); $data = \Wechat\Wxapi::dwz($url); if ($data['errcode'] == '0' && $data['short_url']) { return $data['short_url']; } else { return $url; } }
public function _initialize() { $this->user_id = session('user_id'); #$this->user_id = 2; #return true; $openid = session('openid'); if (!$openid) { $openid = cookie('openid'); if ($openid) { session('openid', $openid); } } if ($openid && empty($this->user_id)) { $user = M('user')->where(array('openid' => $openid))->find(); if ($user) { session('user_id', $user['uin']); $this->user_id = $user['uin']; } } #$this->user_id = 2; if (empty($this->user_id)) { \Wechat\Wxapi::authorize(); exit; } $this->user = M('user')->find($this->user_id); $this->title = $this->user['name'] . "个人中心"; /* if(!session('user.uin')){ header("location: ".U('login/index')); } $this->user = M('user u') ->join('LEFT JOIN __REGION__ p ON p.id=u.province') ->join('LEFT JOIN __REGION__ c ON c.id=u.city') ->join('LEFT JOIN __REGION__ a ON a.id=u.area') ->join('LEFT JOIN __USER_ATTEST__ r ON r.uin=u.uin') ->field('r.status as rstatus,u.uin,u.name,u.phone,u.create_time,u.money,u.points,u.age,u.sex,u.province,u.city,u.area,u.address,u.header,c.name as cityname,p.name as provname,a.name as areaname') ->where(array('u.uin'=>session('user.uin')))->find(); $this->phone=session('user.phone');*/ }
function userinfo() { if (session('openid')) { if ($_GET['token'] && session('openid')) { $user = \Wechat\Wxapi::getUserInfo(session('openid')); } else { $user = \Wechat\Wxapi::getUserInfo(session('openid'), 2); } if ($user) { $user_info = M('user')->where(array('openid' => session('openid')))->find(); if ($user_info) { if ($user['openid']) { $data['name'] = $user['nickname']; // $data['openid'] = $user['openid']; $data['create_time'] = time(); $data['header'] = $user['headimgurl']; $data['sex'] = $user['sex']; $data['unionid'] = $user['unionid']; $data['wx_province'] = $user['province']; $data['wx_city'] = $user['wx_city']; $data['wx_country'] = $user['country']; if ($user['subscribe_time']) { $data['subscribe_time'] = $user['subscribe_time']; } if (isset($user['subscribe'])) { $data['subscribe'] = $user['subscribe']; } if (isset($user['groupid'])) { $data['groupid'] = $user['groupid']; } if (isset($user['remark'])) { $data['remark'] = $user['remark']; } $data['wx_last_time'] = time(); M('user')->where("uin='" . $user_info['uin'] . "'")->save($data); } session('user_id', $user_info['uin']); } else { if ($user['openid']) { // $data['name'] = $user['nickname']; $data['openid'] = $user['openid']; $data['create_time'] = time(); $data['header'] = $user['headimgurl']; $data['sex'] = $user['sex']; $data['unionid'] = $user['unionid']; $data['wx_province'] = $user['province']; $data['wx_city'] = $user['wx_city']; $data['wx_country'] = $user['country']; if ($user['subscribe_time']) { $data['subscribe_time'] = $user['subscribe_time']; } if (isset($user['subscribe'])) { $data['subscribe'] = $user['subscribe']; } if (isset($user['groupid'])) { $data['groupid'] = $user['groupid']; } if (isset($user['remark'])) { $data['remark'] = $user['remark']; } $data['wx_last_time'] = time(); $uin = M('user')->add($data); session('user_id', $uin); } } } else { echo 'ERROR 11'; exit; } } else { // print_r($_SERVER); echo 'ERROR 22'; exit; } $url = urldecode($_GET['url']); if (empty($url)) { $url = U('/zhao/'); } header("location:" . $url . ""); exit; }
/** * 系统初始化 */ public function _initialize() { $this->user_id = session('user_id'); if (I('get.show_test', '', 'strval') == 'test') { $this->user_id = 10004; // return true; } $openid = session('openid'); if (!$openid) { $openid = cookie('openid'); if ($openid) { session('openid', $openid); } } // 系统获取当前用户 if (!$this->user_id) { if ($openid) { // 用户登录 $user = M('user')->where(array('openid' => $openid))->find(); if ($user) { session('subscribe', $user['subscribe']); session('user_id', $user['uin']); $this->user_id = $user['uin']; if ($user['wx_last_time'] < time() - 86400) { if ($user['subscribe']) { // 自动获取 $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; header("Location: " . U("/zjh/weixin/userinfo") . '&url=' . urlencode($url)); } else { // 网页授权 \Wechat\Wxapi::authorize(); exit; } } } else { \Wechat\Wxapi::authorize(); exit; } } else { // 网页授权 \Wechat\Wxapi::authorize(); exit; } } else { $user = M('user')->find($this->user_id); if ($user) { session('user_id', $user['uin']); // echo $user['subscribe'].'-'; session('subscribe', $user['subscribe']); } } $signPackage = \Wechat\Wxapi::getSignPackage(); $this->signPackage = $signPackage; $this->share_title = "私货微群社区"; $this->share_link = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"; $this->share_imgUrl = "http://{$_SERVER['HTTP_HOST']}/images/logo.jpg"; $this->share_desc = "私货微群社区"; $this->subscribe = session('subscribe'); $user = M('user')->find($this->user_id); $this->user = $user; // 自动设置用户 if ($user['qun_user_id'] < 1) { $list = M('qun_user')->where(array('NickName' => $user['name']))->select(); if (count($list) == 1) { M('user')->where(array('uin' => $user['uin']))->save(array('qun_user_id' => $list[0]['id'])); M('qun_user')->where(array('id' => $list[0]['id']))->save(array('user_id' => $user['uin'])); $user['qun_user_id'] = $list[0]['id']; } else { echo $user['name']; echo "找不到对应用户"; } // } $this->qun_user_id = $user['qun_user_id']; // if(!$this->user_id) }
public function Queryorder($transaction_id) { $input = new WxPayOrderQuery(); $input->SetTransaction_id($transaction_id); $result = WxPayApi::orderQuery($input); Log::DEBUG("query:" . json_encode($result)); if (array_key_exists("return_code", $result) && array_key_exists("result_code", $result) && $result["return_code"] == "SUCCESS" && $result["result_code"] == "SUCCESS") { f_log(http_build_query($result), dirname(__FILE__) . '/wzlog.log'); $result['addtime'] = time(); $id = M('pay_log')->add($result); // 更改order 状态 // 更改 hongbao状态 $result['out_trade_no']; $order = M('zhaopian_order')->where("order_sn='{$result['out_trade_no']}'")->find(); $user = M('user')->find($order['user_id']); if ($order) { // 重复操作 if ($order['state'] > 1) { return true; } $order_data = array('pay_id' => $id, 'pay_time' => time(), 'transaction_id' => $result['transaction_id'], 'state' => 2); M('zhaopian_order')->where("id='{$order['id']}'")->save($order_data); $zhaopian = M('zhaopian')->where("id='{$order['hongbao_id']}'")->find(); if ($zhaopian) { $data = array('update_time' => time(), 'total_num' => $zhaopian['total_num'] + 1, 'total_amount' => $zhaopian['total_amount'] + $order['amount']); // 自动发送红包 if (true) { $bao = array('mch_billno' => get_order_sn('wz'), 'send_name' => '红包照片', 're_openid' => $zhaopian['openid'], 'total_amount' => floor($order['amount'] * 0.98 * 100), 'wishing' => '恭喜您!您在照片刚刚"' . $user['name'] . '"购买了', 'act_name' => '红包照片', 'remark' => '红包照片'); $send = $bao; $send['user_id'] = $zhaopian['user_id']; $send['addtime'] = time(); $hongbao_id = M('zhaopian_send')->add($send); if ($hongbao_id) { M('zhaopian_order')->where(array("id='{$order['id']}'"))->save(array('send_id' => $hongbao_id, 'send_sn' => $bao['mch_billno'], 'send_time' => time())); $data = sendHongBao($bao); if ($data['result_code'] == 'SUCCESS' && $data['return_code'] == 'SUCCESS') { M('zhaopian_order')->where(array("id='{$order['id']}'"))->save(array('is_send_zhaopian' => 1)); M('zhaopian_send')->where(array("id='{$hongbao_id}'"))->save(array('state' => 2, 'send_listid' => $data['send_listid'])); $user_amount = number_format($order['amount'] * 0.98, 2); $msg = "你发布的照片有朋友购买了!\n\n照片标题:{$zhaopian['remark']}\n\n支付金额:¥{$order['amount']}元\n\n好友购买照片钱已经通过微信红包打给你,其中已扣除2%微信支付手续费,扣除后金额为{$user_amount}元"; \Wechat\Wxapi::send_wxmsg($zhaopian['openid'], '红包照片状态提醒', U('/zhao/zhaopian/detail', array('id' => $zhaopian['number_no']), true, true), $msg); } else { M('hongbao_send')->where(array("id='{$hongbao_id}'"))->save(array('state' => 3)); $user_amount = number_format($order['amount'] * 0.98, 2); $msg = "你发布的照片有朋友购买了!\n\n照片标题:{$zhaopian['remark']}\n\n支付金额:¥{$order['amount']}元\n\n红包将会在1~3个工作内,通过微信红包打给你,\n其中已扣除2%的微信支付手续费,扣除后金额为{$user_amount}元。\n因为微信支付到我们的账户需要1~3个工作日,我们\n的账户预存垫付的现金不足,暂时不能实时转账,希望\n理解。资金安全请你放心,如果有疑问请联系客服。"; \Wechat\Wxapi::send_wxmsg($zhaopian['openid'], '红包照片状态提醒', U('/zhao/zhaopian/detail', array('id' => $zhaopian['number_no']), true, true), $msg); $sys_openid = "obb1AuA79tIJ-BGY7HA38FXAJwoc"; $msg = "重要提示! 红包发送异常!!! 可能余额不足,或支付金额异常,支付金额:{$user_amount},请及时处理."; \Wechat\Wxapi::send_wxmsg($sys_openid, '红包照片状态提醒', "http://{$_SERVER['HTTP_HOST']}", $msg); } } } } } return true; } return false; }
function sendhongbao() { header("Content-type:text/html;charset=utf-8"); // 设置过期 $list = M('hongbao')->where(array('state' => 1, 'addtime' => array('lt', time() - 86400)))->select(); foreach ($list as $item) { // 设置过期 M('hongbao')->where(array('id' => $item['id']))->save(array('state' => 3)); } $hongbao_list = M('hongbao')->where(array('state' => 2, 'is_send_hongbao' => 0))->select(); foreach ($hongbao_list as $hongbao) { $hongbao_send = M('hongbao_send')->where(array('id' => $hongbao['hongbao_id']))->find(); if (!$hongbao_send) { $bao = array('mch_billno' => get_order_sn(), 'send_name' => '凑红包', 're_openid' => $hongbao['openid'], 'total_amount' => floor($hongbao['total_amount'] * 0.98 * 100), 'wishing' => '恭喜您!您在凑红包发起的凑红包已经完成。', 'act_name' => '凑红包', 'remark' => '凑红包'); $send = $bao; $send['user_id'] = $hongbao['user_id']; $send['addtime'] = time(); $hongbao_id = M('hongbao_send')->add($send); if ($hongbao_id) { M('hongbao')->where(array("id='{$hongbao['id']}'"))->save(array('hongbao_id' => $hongbao_id, 'hongbao_sn' => $bao['mch_billno'], 'hongbao_time' => time())); $hongbao_send = M('hongbao_send')->find($hongbao_id); } } // 发送红包 if ($hongbao_send) { $bao = array('mch_billno' => $hongbao_send['mch_billno'], 'send_name' => '凑红包', 're_openid' => $hongbao['openid'], 'total_amount' => floor($hongbao['total_amount'] * 0.98 * 100), 'wishing' => '恭喜您!您在凑红包发起的凑红包已经完成。', 'act_name' => '凑红包', 'remark' => '凑红包'); $data = sendHongBao($bao); if ($data['result_code'] == 'SUCCESS' && $data['return_code'] == 'SUCCESS') { M('hongbao')->where(array("id='{$hongbao['id']}'"))->save(array('is_send_hongbao' => 1)); M('hongbao_send')->where(array("id='{$hongbao_send['id']}'"))->save(array('state' => 2, 'send_listid' => $data['send_listid'])); // 幸运星 $star = M('hongbao_order')->where(array('hongbao_id' => $hongbao['id'], 'is_star' => 1))->find(); if (!$star) { $list = M('hongbao_order')->where("hongbao_id='{$hongbao['id']}' AND state=2")->select(); if ($list) { $ids = array(); foreach ($list as $r) { $ids[] = $r['id']; } shuffle($ids); $k = array_rand($ids); $id = $ids[$k]; if ($id) { $order_info = M('hongbao_order')->find($id); $user_info = M('user')->find($order_info['user_id']); M('hongbao_order')->where("id='{$id}'")->save(array('is_star' => 1)); } } } else { $user_info = M('user')->find($star['user_id']); } $user_amount = number_format($hongbao['total_amount'] * 0.98, 2); $msg = "你发起的凑红包成功啦!\n\n众筹标题:{$hongbao['remark']}\n\n众筹进度:¥{$hongbao['total_amount']}已成功!\n\n幸运星:{$user_info['name']}\n\n红包已经通过微信红包打给你,其中已扣除2%微信支付手续费,扣除后金额为{$user_amount}元"; \Wechat\Wxapi::send_wxmsg($hongbao['openid'], '众筹状态提醒', U('/cou/hongbao/detail', array('id' => $hongbao['number_no']), true, true), $msg); $msg = "幸运星就是你!没想到吧\n\n众筹标题:{$hongbao['remark']}\n\n众筹进度:¥{$hongbao['total_amount']}已成功!\n\n快找发起人要福利吧 :D"; \Wechat\Wxapi::send_wxmsg($user_info['openid'], '众筹状态提醒', U('/cou/hongbao/detail', array('id' => $hongbao['number_no']), true, true), $msg); $log = "发送红包成功, 红包编号:{$hongbao['id']},发送编号:{$hongbao_send['id']}"; f_log($log, ROOT_PATH . 'Runtime/Logs/hongbao.log'); echo $log . "<br/>"; } else { $log = "发送红包失败, 红包编号:{$hongbao['id']},发送编号:{$hongbao_send['id']}"; f_log($log, ROOT_PATH . 'Runtime/Logs/hongbao.log'); echo $log . "<br/>"; print_r($data); } sleep(5); } } die('ok'); }
public function Queryorder($transaction_id) { $input = new WxPayOrderQuery(); $input->SetTransaction_id($transaction_id); $result = WxPayApi::orderQuery($input); Log::DEBUG("query:" . json_encode($result)); if (array_key_exists("return_code", $result) && array_key_exists("result_code", $result) && $result["return_code"] == "SUCCESS" && $result["result_code"] == "SUCCESS") { f_log(http_build_query($result), dirname(__FILE__) . '/mylog.log'); $result['addtime'] = time(); $id = M('pay_log')->add($result); // 更改order 状态 // 更改 hongbao状态 $order_sn = $result['out_trade_no']; if (substr($order_sn, 0, 2) == 'HB') { $this->bao($result, $id); return true; } if (substr($order_sn, 0, 2) == 'ZP') { $this->zhaopian($result, $id); return true; } $order = M('hongbao_order')->where("order_sn='{$result['out_trade_no']}'")->find(); if ($order) { // 重复操作 if ($order['state'] > 1) { return true; } $order_data = array('pay_id' => $id, 'pay_time' => time(), 'transaction_id' => $result['transaction_id'], 'state' => 2); M('hongbao_order')->where("id='{$order['id']}'")->save($order_data); $hongbao = M('hongbao')->where("id='{$order['hongbao_id']}'")->find(); if ($hongbao) { $data = array('update_time' => time(), 'total_num' => $hongbao['total_num'] + $order['part_num'], 'total_pay_amount' => $hongbao['total_pay_amount'] + $order['total_amount'], 'total_user' => $hongbao['total_user'] + 1); if ($data['total_num'] >= $hongbao['total_part'] || $data['total_pay_amount'] >= $hongbao['total_amount']) { $data['state'] = 2; $data['success_time'] = time(); } M('hongbao')->where("id='{$order['hongbao_id']}'")->save($data); if ($hongbao['state'] > 1) { return true; } // 设置幸运星 if ($data['state'] == 2) { $list = M('hongbao_order')->where("hongbao_id='{$order['hongbao_id']}' AND state=2")->select(); if ($list) { $ids = array(); foreach ($list as $r) { $ids[] = $r['id']; } shuffle($ids); $k = array_rand($ids); $id = $ids[$k]; if ($id) { $order_info = M('hongbao_order')->find($id); $user_info = M('user')->find($order_info['user_id']); M('hongbao_order')->where("id='{$id}'")->save(array('is_star' => 1)); } } } // 自动发送红包 if ($data['state'] == 2) { $bao = array('mch_billno' => get_order_sn(), 'send_name' => '凑红包', 're_openid' => $hongbao['openid'], 'total_amount' => floor($hongbao['total_amount'] * 0.98 * 100), 'wishing' => '恭喜您!您在凑红包发起的凑红包已经完成。', 'act_name' => '凑红包', 'remark' => '凑红包'); $send = $bao; $send['user_id'] = $hongbao['user_id']; $send['addtime'] = time(); $hongbao_id = M('hongbao_send')->add($send); if ($hongbao_id) { M('hongbao')->where(array("id='{$hongbao['id']}'"))->save(array('hongbao_id' => $hongbao_id, 'hongbao_sn' => $bao['mch_billno'], 'hongbao_time' => time())); $data = sendHongBao($bao); if ($data['result_code'] == 'SUCCESS' && $data['return_code'] == 'SUCCESS') { M('hongbao')->where(array("id='{$hongbao['id']}'"))->save(array('is_send_hongbao' => 1)); M('hongbao_send')->where(array("id='{$hongbao_id}'"))->save(array('state' => 2, 'send_listid' => $data['send_listid'])); $user_amount = number_format($hongbao['total_amount'] * 0.98, 2); $msg = "你发起的凑红包成功啦!\n\n众筹标题:{$hongbao['remark']}\n\n众筹进度:¥{$hongbao['total_amount']}已成功!\n\n幸运星:{$user_info['name']}\n\n红包已经通过微信红包打给你,其中已扣除2%微信支付手续费,扣除后金额为{$user_amount}元"; \Wechat\Wxapi::send_wxmsg($hongbao['openid'], '众筹状态提醒', U('/cou/hongbao/detail', array('id' => $hongbao['number_no']), true, true), $msg); $msg = "幸运星就是你!没想到吧\n\n众筹标题:{$hongbao['remark']}\n\n众筹进度:¥{$hongbao['total_amount']}已成功!\n\n快找发起人要福利吧 :D"; \Wechat\Wxapi::send_wxmsg($user_info['openid'], '众筹状态提醒', U('/cou/hongbao/detail', array('id' => $hongbao['number_no']), true, true), $msg); } else { M('hongbao_send')->where(array("id='{$hongbao_id}'"))->save(array('state' => 3)); $user_amount = number_format($hongbao['total_amount'] * 0.98, 2); $msg = "你发起的凑红包成功啦!\n\n众筹标题:{$hongbao['remark']}\n\n众筹进度:¥{$hongbao['total_amount']}已成功!\n\n幸运星:{$user_info['name']}\n\n红包将会在1~3个工作内,通过微信红包打给你,\n其中已扣除2%的微信支付手续费,扣除后金额为{$user_amount}元。\n因为微信支付到我们的账户需要1~3个工作日,我们\n的账户预存垫付的现金不足,暂时不能实时转账,希望\n理解。资金安全请你放心,如果有疑问请联系客服。"; \Wechat\Wxapi::send_wxmsg($hongbao['openid'], '众筹状态提醒', U('/cou/hongbao/detail', array('id' => $hongbao['number_no']), true, true), $msg); $sys_openid = "oV3oMxP5wdTR8BpptzNq2tDdGtLk"; $msg = "重要提示! 红包发送异常!!!"; \Wechat\Wxapi::send_wxmsg($sys_openid, '众筹状态提醒', "http://{$_SERVER['HTTP_HOST']}", $msg); } } } } } return true; } return false; }
if (!$item['pic_url']) { $pic_url = $item['user_id'] . '/' . date("Ymd") . '/zp_' . time() . rand(111, 999) . '.jpg'; $data['pic_url'] = $pic_url; } else { $pic_url = $item['pic_url']; } M('zhaopian_pic')->where(array('id' => $item['id']))->save($data); $pic_path = $root_path . "/uploads/" . $pic_url; if (!file_exists(dirname($pic_path))) { mkdir(dirname($pic_path), 0777, true); } echo $pic_url . "\r\n"; if (!file_exists($pic_path) && filesize($pic_path) < 4028) { echo $item['media_id'] . "\r\n"; $ds = \Wechat\Wxapi::downloadWeixinFile($item['media_id']); \Wechat\Wxapi::saveWeixinFile($pic_path, $ds['body']); } if ($item['is_default']) { M('zhaopian')->where(array('id' => $item['zhaopian_id']))->save(array('pic_url' => $pic_url)); if (file_exists($pic_path)) { $img = new \Think\Image(\Think\Image::IMAGE_IMAGICK); $img->open($pic_path); $width = $img->width(); $height = $img->height(); $x = $y = 0; if ($width > $height) { $x = floor(($width - $height) / 2); $width = $height; } elseif ($height > $width) { $y = floor(($height - $width) / 2); $height = $width;