diff --git a/application/api/controller/User.php b/application/api/controller/User.php index 66108825c4a02da964bbc0ef2111f9c4beee9591..803d683842075a6a1498db97d1b783e28e2fb668 100755 --- a/application/api/controller/User.php +++ b/application/api/controller/User.php @@ -92,7 +92,7 @@ class User extends Common } // 授权 - $result = (new \base\AlipayAuth())->GetAuthCode(MyC('common_app_mini_alipay_appid'), $this->data_post['authcode']); + $result = (new \base\AlipayAuth())->GetAuthSessionKey(MyC('common_app_mini_alipay_appid'), $this->data_post['authcode']); if($result['status'] == 0) { // 先从数据库获取用户信息 @@ -326,10 +326,17 @@ class User extends Common 'appid' => MyC('common_app_mini_toutiao_appid'), 'secret' => MyC('common_app_mini_toutiao_appsecret'), ]; - $result = (new \base\Toutiao())->GetAuthCode($this->data_post); + $result = (new \base\Toutiao())->GetAuthSessionKey($this->data_post); if($result['status'] == 0) { - return DataReturn('授权登录成功', 0, $result['data']['openid']); + // 先从数据库获取用户信息 + $user = UserService::AppUserInfoHandle(null, 'toutiao_openid', $result); + if(empty($user)) + { + return DataReturn('授权登录成功', 0, ['is_alipay_user_exist'=>0, 'openid'=>$result['data']]); + } + $user['is_alipay_user_exist'] = 1; + return DataReturn('授权登录成功', 0, $user); } return DataReturn($result['msg'], -10); } diff --git a/extend/base/AlipayAuth.php b/extend/base/AlipayAuth.php index 5f93f13215c63ad18cf91ea1245161d31956d080..4a47c7685c0f274093bdccf8d1ea3c839e5b779c 100755 --- a/extend/base/AlipayAuth.php +++ b/extend/base/AlipayAuth.php @@ -18,7 +18,12 @@ namespace base; class AlipayAuth { /** - * [GetAuthCode 获取用户授权信息] + * [__construct 构造方法] + */ + public function __construct(){} + + /** + * [GetAuthSessionKey 获取用户授权信息] * @author Devil * @blog http://gong.gg/ * @version 1.0.0 @@ -27,7 +32,7 @@ class AlipayAuth * @param [string] $authcode [用户授权码] * @return [array|boolean] [失败false, 用户授权信息] */ - public function GetAuthCode($app_id, $authcode = '') + public function GetAuthSessionKey($app_id, $authcode = '') { if(empty($app_id) || empty($authcode)) { @@ -70,11 +75,6 @@ class AlipayAuth return ['status'=>-1, 'msg'=>$msg]; } - /** - * [__construct 构造方法] - */ - public function __construct(){} - /** * [GetParamSign 生成参数和签名] * @param [array] $data [待生成的参数] diff --git a/extend/base/AlipayLife.php b/extend/base/AlipayLife.php deleted file mode 100755 index 1a5ad4d1a6d110bda0c2cf00db2fd5d7c6b6db60..0000000000000000000000000000000000000000 --- a/extend/base/AlipayLife.php +++ /dev/null @@ -1,664 +0,0 @@ -params = $params; - $this->xml_data = isset($params['biz_content']) ? $this->XmlToArray($params['biz_content']) : ''; - - // 生活号 - if(!empty($params['life_data'])) - { - $this->life_data = $params['life_data']; - } else { - $this->life_data = isset($this->xml_data['AppId']) ? AlipayLifeService::AppidLifeRow(['appid'=>$this->xml_data['AppId']]) : ''; - } - } - - /** - * [MyRsaSign 签名字符串] - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @datetime 2017-09-24T08:38:28+0800 - * @param [string] $prestr [需要签名的字符串] - * @return [string] [签名结果] - */ - private function MyRsaSign($prestr) - { - $res = "-----BEGIN RSA PRIVATE KEY-----\n"; - $res .= wordwrap($this->life_data['rsa_private'], 64, "\n", true); - $res .= "\n-----END RSA PRIVATE KEY-----"; - return openssl_sign($prestr, $sign, $res, OPENSSL_ALGO_SHA256) ? base64_encode($sign) : null; - } - - /** - * [MyRsaDecrypt RSA解密] - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @datetime 2017-09-24T09:12:06+0800 - * @param [string] $content [需要解密的内容,密文] - * @return [string] [解密后内容,明文] - */ - private function MyRsaDecrypt($content) - { - $res = "-----BEGIN PUBLIC KEY-----\n"; - $res .= wordwrap($this->life_data['rsa_private'], 64, "\n", true); - $res .= "\n-----END PUBLIC KEY-----"; - $res = openssl_get_privatekey($res); - $content = base64_decode($content); - $result = ''; - for($i=0; $ilife_data['out_rsa_public'], 64, "\n", true); - $res .= "\n-----END PUBLIC KEY-----"; - $pkeyid = openssl_pkey_get_public($res); - $sign = base64_decode($sign); - if($pkeyid) - { - $verify = openssl_verify($prestr, $sign, $pkeyid, OPENSSL_ALGO_SHA256); - openssl_free_key($pkeyid); - } - return (isset($verify) && $verify == 1) ? true : false; - } - - /** - * xml转属组 - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @date 2018-10-22 - * @desc description - * @param [string] $xmltext [xml数据] - * @return [array] [属组] - */ - public function XmlToArray($xmltext) - { - $xmltext = iconv("GBK", "UTF-8", urldecode($xmltext)); - $objectxml = simplexml_load_string($xmltext, 'SimpleXMLElement', LIBXML_NOCDATA); - $xmljson = json_encode($objectxml); - return json_decode($xmljson, true); - } - - /** - * 属组转url字符串 - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @date 2018-10-22 - * @desc description - * @param [array] $data [输入参数-数组] - * @return [string] [url字符串] - */ - public function ArrayToUrlString($data) - { - $url_string = ''; - ksort($data); - foreach($data AS $key=>$val) - { - if(!in_array($key, ['sign'])) - { - $url_string .= "$key=$val&"; - } - } - return substr($url_string, 0, -1); - } - - /** - * 返回操作状态 - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @datetime 2018-10-23T01:07:28+0800 - * @param boolean $status [description] - */ - public function Respond($status = false) - { - if($status === true) - { - $response_xml = ''.$this->life_data['rsa_public'].'true'; - } else { - $response_xml = 'VERIFY_FAILED'.$this->life_data['rsa_public'].'false'; - } - $return_xml = ' - - - '.$this->life_data['rsa_public'].' - true - - '.$this->MyRsaSign($response_xml).' - RSA2 - '; - die($return_xml); - } - - /** - * [HttpRequest 网络请求] - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @datetime 2017-09-25T09:10:46+0800 - * @param [string] $url [请求url] - * @param [array] $data [发送数据] - * @return [mixed] [请求返回数据] - */ - private function HttpRequest($url, $data) - { - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_FAILONERROR, false); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - - $body_string = ''; - $encode_array = []; - $post_multipart = false; - if(is_array($data) && 0 < count($data)) - { - foreach($data as $k => $v) - { - if ('@' != substr($v, 0, 1)) - { - $body_string .= $k.'='.urlencode($v).'&'; - $encode_array[$k] = $v; - } else { - $post_multipart = true; - $encode_array[$k] = new \CURLFile(substr($v, 1)); - } - } - } - - curl_setopt($ch, CURLOPT_POST, true); - if($post_multipart === true) - { - curl_setopt($ch, CURLOPT_POSTFIELDS, $encode_array); - - list($s1, $s2) = explode(' ', microtime()); - $millisecond = (float)sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000); - $headers = array('content-type: multipart/form-data;charset=UTF-8;boundary='.$millisecond); - } else { - curl_setopt($ch, CURLOPT_POSTFIELDS, substr($body_string, 0, -1)); - $headers = array('content-type: application/x-www-form-urlencoded;charset=UTF-8'); - } - - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - $reponse = curl_exec($ch); - if(curl_errno($ch)) - { - return false; - } else { - $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); - if(200 !== $httpStatusCode) - { - return false; - } - } - curl_close($ch); - return json_decode($reponse, true); - } - - /** - * 校验 - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @date 2018-10-22 - * @desc description - */ - public function Check() - { - // 当前生活号是否存在 - if(empty($this->life_data)) - { - die('life error'); - } - - // 开始处理 - $status = $this->OutRsaVerify($this->ArrayToUrlString($this->params), $this->params['sign']); - $this->Respond($status); - } - - /** - * 生活号事件 - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @datetime 2018-10-23T00:38:21+0800 - */ - public function Life() - { - // 当前生活号是否存在 - if(empty($this->life_data)) - { - die('life error'); - } - - // 开始处理 - $status = false; - if($this->OutRsaVerify($this->ArrayToUrlString($this->params), $this->params['sign'])) - { - $userinfo = empty($this->xml_data['UserInfo']) ? '' : json_decode($this->xml_data['UserInfo'], true); - $data = [ - 'appid' => $this->xml_data['AppId'], - 'alipay_openid' => $this->xml_data['FromAlipayUserId'], - 'user_id' => empty($this->xml_data['FromUserId']) ? '' : $this->xml_data['FromUserId'], - 'logon_id' => empty($userinfo['logon_id']) ? '' : $userinfo['logon_id'], - 'user_name' => empty($userinfo['user_name']) ? '' : $userinfo['user_name'], - ]; - switch($this->xml_data['EventType']) - { - // 取消关注 - case 'unfollow' : - $status = AlipayLifeService::UserUnfollow($data); - break; - - // 关注/进入生活号 - case 'follow' : - case 'enter' : - $status = AlipayLifeService::UserEnter($data); - break; - } - } - $this->Respond($status); - } - - /** - * [SyncRsaVerify 同步返回签名验证] - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @datetime 2017-09-25T13:13:39+0800 - * @param [array] $data [返回数据] - * @param [boolean] $key [数据key] - */ - private function SyncRsaVerify($data, $key) - { - $string = json_encode($data[$key], JSON_UNESCAPED_UNICODE); - return $this->OutRsaVerify($string, $data['sign']); - } - - /** - * 获取公共参数 - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @date 2018-10-24 - * @desc description - */ - private function RequestCommonParams() - { - return [ - 'app_id' => $this->life_data['appid'], - 'format' => 'JSON', - 'charset' => 'utf-8', - 'sign_type' => 'RSA2', - 'timestamp' => date('Y-m-d H:i:s'), - 'version' => '1.0', - ]; - } - - /** - * 消息发送 - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @date 2018-10-24 - * @desc description - * @param [array] $data [输入参数] - */ - public function MessageSend($params = []) - { - // 参数处理 - $p = $this->RequestCommonParams(); - $p['method'] = $params['method']; - $biz_content = [ - 'msg_type' => ($params['msg_type'] == 0) ? 'text' : 'image-text', - 'chat' => isset($params['chat']) ? intval($params['chat']) : 0, - ]; - - // 消息内容 - if(empty($params['content']) || !is_array($params['content'])) - { - return ['status'=>-1, 'msg'=>'消息内容有误']; - } - - // 发送类型 单条 - if($params['send_type'] == 0) - { - if(empty($params['alipay_openid'])) - { - return ['status'=>-1, 'msg'=>'指定用户openid不能为空']; - } - $biz_content['to_user_id'] = $params['alipay_openid']; - } - - // 消息类型 - if($params['msg_type'] == 1) - { - $biz_content['articles'] = []; - foreach($params['content'] as $k=>$v) - { - if($k < 10) - { - $biz_content['articles'][] = [ - 'title' => $v['title'], - 'desc' => $v['content'], - 'image_url' => $v['out_image_url'], - 'url' => $v['url'], - 'action_name' => $v['action_name'], - ]; - } - } - } else { - $biz_content['text'] = ['content'=>$params['content'][0]['content']]; - } - $p['biz_content'] = json_encode($biz_content, JSON_UNESCAPED_UNICODE); - - // 生成签名 - $p['sign'] = $this->MyRsaSign($this->ArrayToUrlString($p)); - - // 请求接口 - $result = $this->HttpRequest('https://openapi.alipay.com/gateway.do', $p); - $key = str_replace('.', '_', $p['method']).'_response'; - - // 验证签名 - if(!$this->SyncRsaVerify($result, $key)) - { - return ['status'=>-1, 'msg'=>'签名验证错误']; - } - - // 状态 - if(isset($result[$key]['code']) && $result[$key]['code'] == 10000) - { - return ['status'=>0, 'msg'=>'发送成功']; - } - return ['status'=>-100, 'msg'=>$result[$key]['sub_msg'].'['.$result[$key]['code'].']']; - } - - /** - * 单条消息发送 - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @date 2018-10-24 - * @desc description - * @param [array] $data [输入参数] - */ - public function CustomSend($params = []) - { - $params['method'] = 'alipay.open.public.message.custom.send'; - return $this->MessageSend($params); - } - - /** - * 群发消息发送 - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @date 2018-10-24 - * @desc description - * @param [array] $data [输入参数] - */ - public function GroupSend($params = []) - { - $params['method'] = 'alipay.open.public.message.total.send'; - return $this->MessageSend($params); - } - - /** - * 图片上传 - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @date 2018-10-25 - * @desc description - * @param [array] $data [输入参数] - */ - public function UploadImage($params = []) - { - // 参数校验 - if(empty($params['file'])) - { - return ['status'=>-1, 'msg'=>'图片地址有误']; - } - - // 参数处理 - $p = $this->RequestCommonParams(); - $p['method'] = 'alipay.offline.material.image.upload'; - - // 图片参数 - $p['image_type'] = isset($params['image_type']) ? $params['image_type'] : 'jpg'; - $p['image_name'] = isset($params['image_name']) ? $params['image_name'] : 'image'; - - // 生成签名 - $p['sign'] = $this->MyRsaSign($this->ArrayToUrlString($p)); - - // 图片内容不参与签名 - $p['image_content'] = '@'.$params['file']; - - // 请求接口 - $result = $this->HttpRequest('https://openapi.alipay.com/gateway.do', $p); - - // 状态 - if(isset($result['alipay_offline_material_image_upload_response']['code']) && $result['alipay_offline_material_image_upload_response']['code'] == 10000) - { - return ['status'=>0, 'msg'=>'上传成功', 'data'=>$result['alipay_offline_material_image_upload_response']['image_url']]; - } - return ['status'=>-100, 'msg'=>$result['alipay_offline_material_image_upload_response']['sub_msg'].'['.$result['alipay_offline_material_image_upload_response']['code'].']', 'data'=>'']; - } - - /** - * 上架生活号 - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @date 2018-10-30 - * @desc description - * @param [array] $data [输入参数] - */ - public function LifeStatus($params = []) - { - // 参数处理 - $p = $this->RequestCommonParams(); - $p['method'] = $params['method']; - $biz_content = []; - $p['biz_content'] = json_encode($biz_content, JSON_UNESCAPED_UNICODE); - - // 生成签名 - $p['sign'] = $this->MyRsaSign($this->ArrayToUrlString($p)); - - // 请求接口 - $result = $this->HttpRequest('https://openapi.alipay.com/gateway.do', $p); - $key = str_replace('.', '_', $p['method']).'_response'; - - // 验证签名 - if(!$this->SyncRsaVerify($result, $key)) - { - return ['status'=>-1, 'msg'=>'签名验证错误']; - } - - // 状态 - if(isset($result[$key]['code']) && $result[$key]['code'] == 10000) - { - return ['status'=>0, 'msg'=>'操作成功']; - } - - // 是否相同状态下操作 - if(stripos($result[$key]['sub_code'], 'LIFE_ALREADY_DEBARK') !== false || stripos($result[$key]['sub_code'], 'LIFE_ALREADY_ON_PLATFORM') !== false) - { - return ['status'=>0, 'msg'=>$result[$key]['sub_msg'].'['.$result[$key]['code'].']']; - } - - return ['status'=>-100, 'msg'=>$result[$key]['sub_msg'].'['.$result[$key]['code'].']']; - } - - /** - * 上架生活号 - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @date 2018-10-30 - * @desc description - * @param [array] $data [输入参数] - */ - public function LifeAboard($params = []) - { - $params['method'] = 'alipay.open.public.life.aboard.apply'; - return $this->LifeStatus($params); - } - - /** - * 下架生活号 - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @date 2018-10-30 - * @desc description - * @param [array] $data [输入参数] - */ - public function LifeDebark($params = []) - { - $params['method'] = 'alipay.open.public.life.debark.apply'; - return $this->LifeStatus($params); - } - - /** - * 菜单发布 - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @date 2018-10-30 - * @desc description - * @param [array] $data [输入参数] - */ - public function MenuRelease($params = []) - { - // 参数处理 - $p = $this->RequestCommonParams(); - $p['method'] = empty($params['method']) ? 'alipay.open.public.menu.modify' : $params['method']; - $biz_content = [ - 'type' => ($params['type'] == 1) ? 'icon' : 'text', - 'button' => [], - ]; - foreach($params['content'] as $v) - { - $button = [ - 'name' => mb_substr($v['name'], 0, 5, 'utf-8'), - 'action_type' => $v['action_type'], - 'action_param' => $v['action_value'], - ]; - - // 是否为图标 - if($params['type'] == 1) - { - $button['icon'] = $v['out_icon']; - } - - // 不为图标并且存在二级 - if($params['type'] != 1 && !empty($v['items'])) - { - foreach($v['items'] as $vs) - { - $button['sub_button'][] = [ - 'name' => mb_substr($vs['name'], 0, 5, 'utf-8'), - 'action_type' => $vs['action_type'], - 'action_param' => $vs['action_value'], - ]; - } - } - $biz_content['button'][] = $button; - } - $p['biz_content'] = json_encode($biz_content, JSON_UNESCAPED_UNICODE); - - // 生成签名 - $p['sign'] = $this->MyRsaSign($this->ArrayToUrlString($p)); - - // 请求接口 - $result = $this->HttpRequest('https://openapi.alipay.com/gateway.do', $p); - $key = str_replace('.', '_', $p['method']).'_response'; - - // 验证签名 - if(!$this->SyncRsaVerify($result, $key)) - { - return ['status'=>-1, 'msg'=>'签名验证错误']; - } - - // 状态 - if(isset($result[$key]['code']) && $result[$key]['code'] == 10000) - { - return ['status'=>0, 'msg'=>'操作成功']; - } - - // 错误是否为菜单不存在,则重新调用创建接口 - if(stripos($result[$key]['sub_code'], 'MENU_MODIFY_NOT_EXIST') !== false) - { - $params['method'] = 'alipay.open.public.menu.create'; - return $this->MenuRelease($params); - } - - // 失败 - return ['status'=>-100, 'msg'=>$result[$key]['sub_msg'].'['.$result[$key]['code'].'-'.$result[$key]['sub_code'].']']; - } - -} -?> \ No newline at end of file diff --git a/extend/base/Toutiao.php b/extend/base/Toutiao.php index a11fbc114cda5f90065b3da519bb4a2ecf82e060..fe60124088e826ad8c1b66e94c10aa6eee536412 100644 --- a/extend/base/Toutiao.php +++ b/extend/base/Toutiao.php @@ -31,7 +31,7 @@ class Toutiao * @desc description * @param [array] $params [输入参数] */ - public function GetAuthCode($params = []) + public function GetAuthSessionKey($params = []) { if(empty($params['authcode'])) { @@ -49,7 +49,7 @@ class Toutiao { return ['status'=>-1, 'msg'=>$result['errmsg']]; } - return ['status'=>0, 'msg'=>'授权成功', 'data'=>$result]; + return ['status'=>0, 'msg'=>'授权成功', 'data'=>$result['openid']]; } /** diff --git a/public/appmini/old/qq/pages/goods-detail/goods-detail.js b/public/appmini/old/qq/pages/goods-detail/goods-detail.js index 5b2c2272f4e4a7daa4af18b773748f9ba54eb98a..9fefa0f814361cbe1ffd64432b7e6684d17c4bf4 100755 --- a/public/appmini/old/qq/pages/goods-detail/goods-detail.js +++ b/public/appmini/old/qq/pages/goods-detail/goods-detail.js @@ -34,7 +34,6 @@ Page({ goods_video_is_autoplay: false, common_app_is_use_mobile_detail: 1, - popup_share_status: false, common_app_is_online_service: 0, // 限时秒杀插件 @@ -697,16 +696,6 @@ Page({ this.setData({ goods_video_is_autoplay: false }); }, - // 分享开启弹层 - popup_share_event(e) { - this.setData({ popup_share_status: true }); - }, - - // 分享弹层关闭 - popup_share_close_event(e) { - this.setData({ popup_share_status: false }); - }, - // 显示秒杀插件-倒计时 plugins_limitedtimediscount_countdown() { // 销毁之前的任务 diff --git a/public/appmini/old/toutiao/app.js b/public/appmini/old/toutiao/app.js index 75c2c8c81a83a62a9ab685b95d73291f25cab9de..f8b2c35fb835f7595b4db7072a0b53eda67419c3 100755 --- a/public/appmini/old/toutiao/app.js +++ b/public/appmini/old/toutiao/app.js @@ -67,7 +67,7 @@ App({ // 请求地址 request_url: "{{request_url}}", - // request_url: 'http://tp5-dev.com/', + request_url: 'http://tp5-dev.com/', // request_url: 'https://test.shopxo.net/', // 基础信息 @@ -154,6 +154,24 @@ App({ ); }, + /** + * 获取用户信息,信息不存在则唤醒授权 + * object 回调操作对象 + * method 回调操作对象的函数 + * return 有用户数据直接返回, 则回调调用者 + */ + get_user_info(object, method) { + var user = this.get_user_cache_info(); + if (user == false) { + // 唤醒用户授权 + this.user_login(object, method); + + return false; + } else { + return user; + } + }, + /** * 从缓存获取用户信息 */ @@ -195,38 +213,82 @@ App({ * method 回调操作对象的函数 */ user_login(object, method) { - var self = this; - tt.login({ - success: (res) => { - if (res.code) { - tt.request({ - url: self.get_request_url('toutiaouserauth', 'user'), - method: 'POST', - data: { authcode: res.code, anonymous_code: res.anonymousCode }, - dataType: 'json', - header: { 'content-type': 'application/x-www-form-urlencoded' }, - success: (res) => { - if (res.data.code == 0) { - tt.setStorage({ - key: self.data.cache_user_login_key, - data: res.data.data - }); - self.get_user_login_info(object, method, res.data.data); - } else { + var openid = tt.getStorageSync(this.data.cache_user_login_key) || null; + if (openid == null) + { + var self = this; + // 加载loding + tt.showLoading({ title: "授权中..." }); + + tt.login({ + success: (res) => { + if (res.code) { + tt.request({ + url: self.get_request_url('toutiaouserauth', 'user'), + method: 'POST', + data: { authcode: res.code, anonymous_code: res.anonymousCode }, + dataType: 'json', + header: { 'content-type': 'application/x-www-form-urlencoded' }, + success: (res) => { tt.hideLoading(); - self.showToast(res.data.msg); - } - }, - fail: () => { - tt.hideLoading(); - self.showToast('服务器请求出错'); - }, + if (res.data.code == 0) { + var data = res.data.data; + if ((data.is_alipay_user_exist || 0) == 1) { + tt.setStorage({ + key: self.data.cache_user_info_key, + data: data, + success: (res) => { + if (typeof object === 'object' && (method || null) != null) { + object[method](); + } + }, + fail: () => { + self.showToast('用户信息缓存失败'); + } + }); + } else { + tt.setStorage({ + key: self.data.cache_user_login_key, + data: data.openid + }); + self.login_to_auth(); + } + } else { + self.showToast(res.data.msg); + } + }, + fail: () => { + tt.hideLoading(); + self.showToast('服务器请求出错'); + }, + }); + } + }, + fail: (e) => { + tt.hideLoading(); + self.showToast('授权失败'); + } + }); + } else { + this.login_to_auth(); + } + }, + + /** + * 跳转到登录页面授权 + */ + login_to_auth() { + tt.showModal({ + title: '温馨提示', + content: '授权用户信息', + confirmText: '确认', + cancelText: '暂不', + success: (result) => { + if (result.confirm) { + tt.navigateTo({ + url: "/pages/login/login" }); } - }, - fail: (e) => { - tt.hideLoading(); - self.showToast('授权失败'); } }); }, @@ -582,6 +644,36 @@ App({ }); }, + // 位置权限获取 + location_authorize(object, method, params) { + var self = this; + tt.getSetting({ + success(res) { + if (!res.authSetting['scope.userLocation']) { + tt.authorize({ + scope: 'scope.userLocation', + success (res) { + if (typeof object === 'object' && (method || null) != null) { + object[method](params); + } + }, + fail (res) { + tt.openSetting(); + self.showToast('请同意地理位置授权'); + } + }); + } else { + if (typeof object === 'object' && (method || null) != null) { + object[method](params); + } + } + }, + fail: (e) => { + self.showToast("授权校验失败"); + } + }); + }, + // 拨打电话 call_tel(value) { if ((value || null) != null) { @@ -589,24 +681,16 @@ App({ } }, - // 登录校验 - is_login_check(res) { + /** + * 登录校验 + * object 回调操作对象 + * method 回调操作对象的函数 + */ + is_login_check(res, object, method) { if(res.code == -400) { tt.clearStorage(); - tt.showModal({ - title: '温馨提示', - content: '授权用户信息', - confirmText: '确认', - cancelText: '暂不', - success: (result) => { - if (result.confirm) { - tt.navigateTo({ - url: "/pages/login/login?event_callback=init" - }); - } - }, - }); + this.get_user_info(object, method); return false; } return true; diff --git a/public/appmini/old/toutiao/app.json b/public/appmini/old/toutiao/app.json index edd9640cf9f9927e22326a6e0ea8f0e788f365da..8ee57b374947301bdf1ec242544898b539ec5972 100755 --- a/public/appmini/old/toutiao/app.json +++ b/public/appmini/old/toutiao/app.json @@ -27,7 +27,8 @@ "pages/user-orderaftersale/user-orderaftersale", "pages/user-orderaftersale-detail/user-orderaftersale-detail", "pages/coupon/coupon", - "pages/user-coupon/user-coupon" + "pages/user-coupon/user-coupon", + "pages/extraction-address/extraction-address" ], "window": { "navigationBarTitleText": "{{application_title}}", diff --git a/public/appmini/old/toutiao/pages/answer-form/answer-form.js b/public/appmini/old/toutiao/pages/answer-form/answer-form.js index f6101ffc00bdb10e63e76fbb5cd1845f7114f6ec..95a78b7a0a793b80cf222f95ab0610ad280fc22e 100755 --- a/public/appmini/old/toutiao/pages/answer-form/answer-form.js +++ b/public/appmini/old/toutiao/pages/answer-form/answer-form.js @@ -13,13 +13,15 @@ Page({ // 初始化 init() { - var user = app.get_user_cache_info(this, "init"); - // 用户未绑定用户则转到登录页面 - if (app.user_is_need_login(user)) { - tt.redirectTo({ - url: "/pages/login/login?event_callback=init" - }); - return false; + var user = app.get_user_info(this, "init"); + if (user != false) { + // 用户未绑定用户则转到登录页面 + if (app.user_is_need_login(user)) { + tt.redirectTo({ + url: "/pages/login/login?event_callback=init" + }); + return false; + } } }, @@ -60,8 +62,11 @@ Page({ }, 2000); } else { this.setData({form_submit_loading: false}); - - app.showToast(res.data.msg); + if (app.is_login_check(res.data)) { + app.showToast(res.data.msg); + } else { + app.showToast('提交失败,请重试!'); + } } }, fail: () => { diff --git a/public/appmini/old/toutiao/pages/buy/buy.js b/public/appmini/old/toutiao/pages/buy/buy.js index 95794eb7e36dfac55be4e53cc1069d920e920c01..8b989b00dc70f3949b436fffaa35d497c36dbfd7 100755 --- a/public/appmini/old/toutiao/pages/buy/buy.js +++ b/public/appmini/old/toutiao/pages/buy/buy.js @@ -8,13 +8,15 @@ Page({ payment_list: [], goods_list: [], address: null, - address_id: 0, + address_id: null, total_price: 0, user_note_value: '', is_first: 1, extension_data: [], payment_id: 0, common_order_is_booking: 0, + common_site_type: 0, + extraction_address: [], // 优惠劵 plugins_coupon_data: null, @@ -23,17 +25,9 @@ Page({ popup_plugins_coupon_status: false, }, onLoad(params) { - if((params.data || null) == null || app.get_length(JSON.parse(params.data)) == 0) + //params['data'] = '{"buy_type":"goods","goods_id":"1","stock":"1","spec":"[]"}'; + if((params.data || null) != null && app.get_length(JSON.parse(params.data)) > 0) { - tt.alert({ - title: '温馨提示', - content: '订单信息有误', - buttonText: '确认', - success: () => { - tt.navigateBack(); - }, - }); - } else { this.setData({ params: JSON.parse(params.data)}); // 删除地址缓存 @@ -42,13 +36,22 @@ Page({ }, onShow() { - tt.setNavigationBarTitle({title: app.data.common_pages_title.buy}); this.init(); - this.setData({is_first: 0}); + this.setData({ is_first: 0 }); }, // 获取数据列表 init() { + // 订单参数信息是否正确 + if (this.data.params == null) { + this.setData({ + data_list_loding_status: 2, + data_list_loding_msg: '订单信息有误', + }); + tt.stopPullDownRefresh(); + return false; + } + // 本地缓存地址 if(this.data.is_first == 0) { @@ -57,12 +60,7 @@ Page({ { this.setData({ address: cache_address, - address_id: cache_address.id - }); - } else { - this.setData({ - address: null, - address_id: 0 + address_id: cache_address.id || null, }); } } @@ -97,6 +95,8 @@ Page({ extension_data: data.extension_data || [], data_list_loding_status: 3, common_order_is_booking: data.common_order_is_booking || 0, + common_site_type: data.common_site_type || 0, + extraction_address: data.base.extraction_address || [], plugins_coupon_data: data.plugins_coupon_data || null, }); @@ -113,19 +113,14 @@ Page({ } // 地址 - if (this.data.address == null || this.data.address_id == 0) { - if((data.base.address || null) != null) { - this.setData({ - address: data.base.address, - address_id: data.base.address.id, - }); - - tt.setStorage({ - key: app.data.cache_buy_user_address_select_key, - data: data.base.address, - }); - } - } + this.setData({ + address: data.base.address || null, + address_id: ((data.base.address || null) != null && (data.base.address.id || null) != null) ? data.base.address.id : null, + }); + tt.setStorage({ + key: app.data.cache_buy_user_address_select_key, + data: data.base.address || null, + }); // 支付方式 this.payment_list_data(data.payment_list); @@ -135,7 +130,9 @@ Page({ data_list_loding_status: 2, data_list_loding_msg: res.data.msg, }); - app.showToast(res.data.msg); + if (app.is_login_check(res.data, this, 'init')) { + app.showToast(res.data.msg); + } } }, fail: () => { @@ -171,9 +168,11 @@ Page({ data['coupon_id'] = this.data.plugins_use_coupon_id; // 数据验证 - var validation = [ - { fields: 'address_id', msg: '请选择地址' } - ]; + var validation = []; + if (this.data.common_site_type == 0 || this.data.common_site_type == 2) + { + validation.push({ fields: 'address_id', msg: '请选择地址', is_can_zero: 1 }); + } if (this.data.common_order_is_booking != 1) { validation.push({ fields: 'payment_id', msg: '请选择支付方式' }); } @@ -263,4 +262,21 @@ Page({ this.init(); }, + // 地址选择事件 + address_event(e) { + if(this.data.common_site_type == 0) + { + tt.navigateTo({ + url: '/pages/user-address/user-address?is_back=1' + }); + } else if (this.data.common_site_type == 2) + { + tt.navigateTo({ + url: '/pages/extraction-address/extraction-address?is_back=1' + }); + } else { + app.showToast('当前模式不允许使用地址'); + } + }, + }); diff --git a/public/appmini/old/toutiao/pages/buy/buy.ttml b/public/appmini/old/toutiao/pages/buy/buy.ttml index 3a91e5bbb939a7435546150b018a23f8db1a2b61..bffa82ef7801c50b78fccbd8c2c7d2963fbf4f11 100755 --- a/public/appmini/old/toutiao/pages/buy/buy.ttml +++ b/public/appmini/old/toutiao/pages/buy/buy.ttml @@ -1,125 +1,132 @@ - - - - - - - {{address.name}} - {{address.tel}} + + + + + + + + + + + + {{address.alias}} + {{address.name}} + {{address.tel}} + + + + {{address.province_name}}{{address.city_name}}{{address.county_name}}{{address.address}} + - - - {{address.province_name}}{{address.city_name}}{{address.county_name}}{{address.address}} + + 请选择地址 - - 请选择地址 - - - - + + - - - - - - {{item.title}} - - {{spec.type}}:{{spec.value}} - - - - - ¥{{item.price}} - - ¥{{item.original_price}} - - x{{item.stock}} - + + + + + + {{item.title}} + + {{spec.type}}:{{spec.value}} + + + + + ¥{{item.price}} + + ¥{{item.original_price}} + + x{{item.stock}} + + - - - -