public function index() { $id = $_GET['id']; $due = false; if ($id) { $itemsMdl = D('Items'); $id = \Common\Lib\Idhandler::decode($id); $item = $itemsMdl->getRow(array('id' => $id)); $itemsMdl->saveData(array('id' => $id, 'visits' => $item['visits'] + 1)); $this->assign('item', $item); if ($item['due_at'] < time()) { $due = true; } } $this->assign('due', $due); $app = ''; $agent = strtolower($_SERVER['HTTP_USER_AGENT']); \Common\Lib\Utils::log('show', 'agent.log', $agent); if (strpos($agent, 'android')) { $app = 'android'; } elseif (strpos($agent, 'iphone') || strpos($agent, 'ipad')) { $app = 'ios'; } $wechat = 0; if (strpos($agent, 'micromessenger')) { $wechat = 1; } $this->assign('app', $app); $this->assign('wechat', $wechat); $this->display(); }
public function index() { \Common\Lib\Utils::log('wechat', 'notify.log', $_SERVER); \Common\Lib\Utils::log('wechat', 'notify.log', $_GET); \Common\Lib\Utils::log('wechat', 'notify.log', $_POST); echo "success"; exit; }
public function back() { \Common\Lib\Utils::log('alipay', 'back.log', $_GET); $alipay_config = C('ALIPAY_CONFIG'); //计算得出通知验证结果 $alipayNotify = new \AlipayNotify($alipay_config); $verify_result = $alipayNotify->verifyReturn(); if ($verify_result) { //验证成功 //请在这里加上商户的业务逻辑程序代码 //——请根据您的业务逻辑来编写程序(以下代码仅作参考)—— //获取支付宝的通知返回参数,可参考技术文档中页面跳转同步通知参数列表 //商户订单号 $out_trade_no = \Common\Lib\Idhandler::decode($_GET['out_trade_no']); //支付宝交易号 $trade_no = $_GET['trade_no']; //交易状态 $trade_status = $_GET['trade_status']; \Common\Lib\Utils::log('trade', 'alipay.log', $_GET); if ($_GET['trade_status'] == 'TRADE_FINISHED' || $_GET['trade_status'] == 'TRADE_SUCCESS') { $tradeMdl = D('Trade'); $params = array('id' => $out_trade_no, 'status' => 'success', 'pay_from' => 'taobao', 'pay_no' => $trade_no, 'paid_at' => time(), 'updated_at' => time()); \Common\Lib\Utils::log('trade', 'alipay.log', $params); $res = $tradeMdl->saveData($params); \Common\Lib\Utils::log('trade', 'alipay.log', $res); if ($res['status'] == 'success') { $trade = $tradeMdl->getRow(array('id' => $out_trade_no)); \Common\Lib\Utils::log('trade', 'alipay.log', $trade); //更新用户的due_at $level = $trade['level']; switch ($level) { case '1': $due_at = time() + 5 * 86400; break; case '2': $due_at = time() + 30 * 86400; break; default: break; } $userMdl = D('User'); $uparams['id'] = $trade['user_id']; $uparams['due_at'] = $due_at; \Common\Lib\Utils::log('trade', 'alipay.log', $uparams); $res = $userMdl->saveData($uparams); \Common\Lib\Utils::log('trade', 'alipay.log', $res); //更新有效商品的时间 $sql = "update items set due_at = {$due_at} where user_id = {$trade['user_id']} and due_at > " . time(); \Common\Lib\Utils::log('trade', 'alipay.log', $sql); $res = $tradeMdl->execute($sql); \Common\Lib\Utils::log('trade', 'alipay.log', $res); echo "<script>localtion.href='/home/pay/success'</script>"; exit; } //判断该笔订单是否在商户网站中已经做过处理 //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序 //如果有做过处理,不执行商户的业务程序 } else { echo "trade_status=" . $_GET['trade_status']; } echo "验证成功<br />"; //——请根据您的业务逻辑来编写程序(以上代码仅作参考)—— ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// } else { //验证失败 //如要调试,请看alipay_notify.php页面的verifyReturn函数 echo "验证失败"; } exit; }
public function short_url($str) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://dwz.cn/create.php"); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $data = array('url' => $str); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $strRes = curl_exec($ch); curl_close($ch); $arrResponse = json_decode($strRes, true); \Common\Lib\Utils::log('wechat', 'request.log', $arrResponse); $url = ''; if ($arrResponse['status'] == 0) { $url = $arrResponse['tinyurl']; } return $url; }
/** * 配置菜单 保存 */ function saveMenu() { header('Content-type: application/json'); $url = '/admin/weixin/menu'; $menuMdl = D('Menu'); $data = $_POST; $first = $menuMdl->getList(0); $first_count = count($first); if ($first_count >= 3 && !$data['id']) { echo json_encode(array('status' => 'error', 'msg' => '最多添加3个一级菜单')); exit; } if (isset($data['sec'])) { $sec_count = count($data['sec']); if ($data['sec'] && $sec_count > 5) { echo json_encode(array('status' => 'error', 'msg' => '最多添加5个二级菜单')); exit; } } $first_len = strlen($data['name']); if ($first_len > 16) { echo json_encode(array('status' => 'error', 'msg' => '一级菜单最多16个字符')); exit; } $weixinMdl = D('Weixin'); if (isset($data['id']) && $data['id']) { $loc_info['id'] = (int) $data['id']; } $loc_info['name'] = $data['name']; $loc_info['weight'] = (int) $data['weight']; $loc_info['parent_id'] = 0; $loc_info['active_state'] = 0; $loc_info['keyword_type'] = 'get'; $loc_info['original_id'] = $info['original_id']; $loc_info['msg_type'] = 'menu'; $loc_info['content'] = ''; //先保存到本地 if ($data['s'] == 'reply') { //回复内容 $loc_info['type'] = 'view'; if ($data['first']['Which-one'] == '2' || $data['first']['Which-one'] == '3') { $loc_info['type'] = 'click'; } if ($data['first']['Which-one'] == '0') { $loc_info['msg_data'] = serialize(array('text' => $data['act_text'][0], 'url' => $data['act_url'][0])); $loc_info['msg_info_type'] = '0'; } if ($data['first']['Which-one'] == '1') { $loc_info['msg_data'] = serialize(array('url' => $data['url'][0])); $loc_info['msg_info_type'] = '0'; } if ($data['first']['Which-one'] == '2') { $qq = json_decode(str_replace('\\n', '', $data['qq'][0]), true); if ($qq['content']) { $content = htmlspecialchars((string) $qq['content'], ENT_QUOTES); if (isset($content[601])) { echo json_encode(array('status' => 'error', 'msg' => '文字回复内容请调整到600字以内')); exit; } $loc_info['msg_info_type'] = '1'; $loc_info['content'] = $qq['content']; } } if ($data['first']['Which-one'] == '3') { $qq = json_decode(str_replace('\\n', '', $data['qq'][0]), true); if ($qq['items']) { foreach ($qq['items'] as &$qi) { if (!$qi['picurl'] && $qi['image']) { $qi['picurl'] = $qi['image']; } } $loc_info['msg_info_type'] = '2'; if ($qq['sorted_ids'] && count($qq['items']) > 1) { $loc_info['sorted_ids'] = $qq['sorted_ids']; $ids = explode(',', $loc_info['sorted_ids']); $loc_info['msg_data'] = $this->multi_array_sort($qq['items'], $ids); } else { $loc_info['msg_data'] = $qq['items']; } $loc_info['msg_data'] = serialize($loc_info['msg_data']); } } if (!$menuMdl->saveData($loc_info)) { echo json_encode(array('status' => 'error', 'msg' => '保存一级菜单失败')); exit; } if (!empty($data['sec'])) { foreach ($data['sec'] as $key => $val) { if ($val['parent_id'] && $val['id'] && !$val['name']) { $menuMdl->deleteOp($val['id']); unset($data['sec'][$key]); continue; } } } } elseif ($data['s'] == 'sub') { $loc_info['type'] = 'sub'; //$loc_info['type'] = $data['first']['Which-one']=='2'?'click':'view'; $loc_info['msg_info_type'] = '0'; $loc_info['msg_data'] = ''; //$rs = $wmenu_mdl->doUpdate($loc_info); $rs = $menuMdl->saveData($loc_info); if (!$rs) { echo json_encode(array('status' => 'error', 'msg' => '保存一级菜单失败')); exit; } //检查提交的内容是否有问题 if (isset($data['sec']) && is_array($data['sec'])) { foreach ($data['sec'] as $key => $val) { $sec_len = strlen($val['name']); if ($sec_len > 40) { echo json_encode(array('status' => 'error', 'msg' => '二级菜单标题最多40个字符')); exit; } if ($val['Which-one'] == '2') { $qq = json_decode(str_replace('\\n', '', $val['qq']), true); if ($qq['content']) { $content = htmlspecialchars((string) $qq['content'], ENT_QUOTES); if (isset($content[601])) { echo json_encode(array('status' => 'error', 'msg' => '文字回复内容请调整到600字以内')); exit; } } } } } //先删除已有的 $rs_del = $menuMdl->deleteByPid($loc_info['id']); if (!$rs_del) { \Common\Lib\Utils::log('wechat', 'wechat.log', '删除失败'); echo json_decode(array('status' => 'error', 'msg' => '保存失败')); exit; } unset($loc_info['id']); //开始创建新提交的内容 foreach ($data['sec'] as $key => $val) { $loc_info['name'] = $val['name']; $loc_info['weight'] = (int) $val['weight']; $loc_info['parent_id'] = $rs; $loc_info['type'] = $val['Which-one'] == '2' ? 'click' : 'view'; if ($val['Which-one'] == '0') { $loc_info['msg_data'] = serialize(array('text' => $val['act_text'], 'url' => $val['act_url'])); $loc_info['msg_info_type'] = '0'; } if ($val['Which-one'] == '1') { $loc_info['msg_data'] = serialize(array('url' => $val['url'])); $loc_info['msg_info_type'] = '1'; } if ($val['Which-one'] == '2') { $qq = json_decode(str_replace('\\n', '', $val['qq']), true); $loc_info['msg_info_type'] = '0'; if ($qq['content']) { unset($loc_info['msg_data']); $loc_info['msg_info_type'] = '1'; $loc_info['content'] = $qq['content']; } } if ($val['Which-one'] == '3') { $qq = json_decode(str_replace('\\n', '', $val['qq']), true); $loc_info['msg_info_type'] = '0'; if ($qq['items']) { foreach ($qq['items'] as &$qi) { if (!$qi['picurl'] && $qi['image']) { $qi['picurl'] = $qi['image']; } } unset($loc_info['content']); $loc_info['msg_info_type'] = '2'; if ($qq['sorted_ids'] && count($qq['items']) > 1) { $loc_info['sorted_ids'] = $qq['sorted_ids']; $ids = explode(',', $qq['sorted_ids']); $loc_info['msg_data'] = $this->multi_array_sort($qq['items'], $ids); } else { $loc_info['msg_data'] = $qq['items']; } $loc_info['msg_data'] = serialize($loc_info['msg_data']); } } if (!$menuMdl->saveData($loc_info)) { echo json_encode(array('status' => 'error', 'msg' => '保存二级菜单失败')); exit; } unset($loc_info['id']); } } $rs = $menuMdl->selectMenu($this->weixin); //$logfile = RUNTIME_PATH . 'Logs/request.log'; //error_log(json_encode($rs) . "\n", 3, $logfile); \Common\Lib\Utils::log('wechat', 'wechat.log', $rs); if ($rs['status'] == 'success') { echo json_encode(array('status' => 'success')); exit; } else { echo json_encode(array('status' => 'error', 'msg' => '保存失败')); exit; } }
protected function reply($message, $userid = '') { if (!$message) { //do nothing $this->_wechat->text('欢迎使用微淘秀')->reply(); } if (1 == $message['msg_info_type']) { $text = str_replace('<br />', "\n", $message['content']); $text = str_replace('target="_blank"', '', $text); $text = str_replace(' ', ' ', $text); $text = $text ? $text : '欢迎使用微淘秀'; $this->_wechat->text($text)->reply(); } else { $data = unserialize($message['msg_data']); \Common\Lib\Utils::log('wechat', 'request.log', $data); $news = array(); foreach ($data as $v) { \Common\Lib\Utils::log('wechat', 'request.log', $v); if ($userid && $v['url']) { $v['url'] = str_replace("{id}", $userid, $v['url']); } \Common\Lib\Utils::log('wechat', 'request.log', $v); $news[] = array('Title' => $v['title'], 'Description' => $v['text'], 'PicUrl' => $v['picurl'], 'Url' => $v['url']); } \Common\Lib\Utils::log('wechat', 'request.log', $news); $this->_wechat->news($news)->reply(); } }
public function success() { $out_trade_no = \Common\Lib\Idhandler::decode($_GET['out_trade_no']); $trade_no = $_GET['trade_no']; $trade_status = $_GET['trade_status']; \Common\Lib\Utils::log('trade', 'alipay.log', $_GET); if ($_GET['trade_status'] == 'TRADE_FINISHED' || $_GET['trade_status'] == 'TRADE_SUCCESS') { $tradeMdl = D('Trade'); $trade = $tradeMdl->getRow(array('id' => $out_trade_no)); if ($trade && $trade['status'] != 'success' && $trade['pay_no'] == '') { $params = array('id' => $out_trade_no, 'status' => 'success', 'pay_from' => 'taobao', 'pay_no' => $trade_no, 'paid_at' => time(), 'updated_at' => time(), 'pay_user' => $_GET['buyer_email']); \Common\Lib\Utils::log('trade', 'alipay.log', $params); $res = $tradeMdl->saveData($params); \Common\Lib\Utils::log('trade', 'alipay.log', $res); $userMdl = D('User'); $user = $userMdl->getRow(array('id' => $trade['user_id'])); $due_at = $user['due_at']; if ($due_at < time()) { $due_at = time(); } //更新用户的due_at $level = $trade['level']; switch ($level) { case '2': $due_at += 7 * 86400; break; case '3': $due_at += 30 * 86400; break; default: break; } $uparams['id'] = $trade['user_id']; $uparams['level'] = $level; $uparams['due_at'] = $due_at; \Common\Lib\Utils::log('trade', 'alipay.log', $uparams); $res = $userMdl->saveData($uparams); \Common\Lib\Utils::log('trade', 'alipay.log', $res); //更新有效商品的时间 $sql = "update items set due_at = {$due_at} where uid = {$trade['user_id']} and due_at > " . time(); \Common\Lib\Utils::log('trade', 'alipay.log', $sql); $res = $tradeMdl->execute($sql); } //更新用户的due_at $level = $trade['level']; $level_str = ''; switch ($level) { case '2': $level_str = '银牌会员'; break; case '3': $level_str = '金牌会员'; break; default: $level_str = "您还不是会员, <a href='/home/pay/index'>成为会员</a>"; break; } \Common\Lib\Utils::log('trade', 'alipay.log', $res); $this->assign('level', $level_str); } else { $this->assign('error', '支付失败'); } $this->display(); }
/** * 生成Native支付二维码链接 * 静态链接 * */ public function getNativeShortUrl($productId, $skuId) { $nonceStr = $this->generateNonceStr(16); $arrdata = array("appid" => $this->appid, "mch_id" => $this->mchid, "long_url" => $this->getNativeUrl($productId, $skuId), "nonce_str" => $nonceStr); $sign = $this->getPaySignature($arrdata); $arrdata['sign'] = $sign; \Common\Lib\Utils::log('wechat', 'wechat.log', $arrdata); \Common\Lib\Utils::log('wechat', 'wechat.log', $this->appsecret); $apiUrl = self::MCH_API_URL_PREFIX . self::MCH_SHORT_URL; $result = $this->http_post($apiUrl, $this->xml_encode($arrdata)); \Common\Lib\Utils::log('wechat', 'wechat.log', $result); $urlxml = (array) simplexml_load_string($result, 'SimpleXMLElement', LIBXML_NOCDATA); \Common\Lib\Utils::log('wechat', 'wechat.log', $urlxml); if ('SUCCESS' == $urlxml['return_code']) { return $urlxml['short_url']; } else { return false; } }