rabin 6 months ago
parent
commit
3e4522b393

+ 64 - 0
src/cate/api/Goods.php

@@ -0,0 +1,64 @@
+<?php namespace Cate\Api;
+use Dever;
+class Goods
+{
+    # 导入数据
+    public function import_commit(){}
+    public function import()
+    {
+        $config = Dever::config('goods_cate')['json'];
+        $config = Dever::json_decode($config);
+        foreach ($config as $k => $v) {
+            if ($v) {
+                $v = array_values($v);
+                $t = count($v);
+                if ($t == 3) {
+                    $level_2_sort = 0;
+                    $level_3_sort = 0;
+                    $level_1 = $this->create(1, $k, $v[0]);
+                    $level_2 = $this->create(2, $level_2_sort, $v[1], $level_1);
+                    $this->create(3, $level_3_sort, $v[2], $level_2, $level_1);
+                } elseif ($t == 2) {
+                    $level_2_sort += 1;
+                    $level_2 = $this->create(2, $level_2_sort, $v[0], $level_1);
+                    $this->create(3, $level_3_sort, $v[1], $level_2, $level_1);
+                }
+            }
+        }
+        return 'ok';
+    }
+
+    private function create($level, $sort, $name, $parent_id = false, $top_id = false)
+    {
+        $sort += 1;
+        if ($level == 3 && strstr($name, '/')) {
+            $name = explode('/', $name);
+            foreach ($name as $k => $v) {
+                $this->create($level, $k, $v, $parent_id, $top_id);
+            }
+            return;
+        }
+        $data['sort'] = $sort;
+        if ($name == '其他') {
+            $data['sort'] = 10000;
+        }
+        $data['name'] = $name;
+        if ($parent_id) {
+            $data['parent_id'] = $parent_id;
+        }
+        if ($top_id) {
+            $data['top_id'] = $top_id;
+            $data['parent'] = $data['top_id'] . ',' . $data['parent_id'];
+        }
+        $icon = Dever::load('icon', 'cate')->get($data['name']);
+        if ($icon) {
+            $data['icon_id'] = $icon['id'];
+        }
+        $db = Dever::db('goods_level_' . $level);
+        $info = $db->find($data);
+        if (!$info) {
+            return $db->insert($data);
+        }
+        return $info['id'];
+    }
+}

+ 6 - 0
src/cate/index.php

@@ -0,0 +1,6 @@
+<?php
+define('DEVER_APP_NAME', 'cate');
+define('DEVER_APP_LANG', '分类');
+define('DEVER_APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+include(DEVER_APP_PATH . '../place/boot.php');
+include(DEVER_APP_PATH . '../../boot.php');

+ 29 - 0
src/cate/lib/Goods.php

@@ -0,0 +1,29 @@
+<?php namespace Cate\Lib;
+use Dever;
+class Goods
+{
+    public function getManageList()
+    {
+        $where = array('status' => 1);
+        $parent = Dever::db('goods_level_1', 'cate')->select($where);
+        $result = array();
+        foreach ($parent as $k => $v) {
+            $where['parent_id'] = $v['id'];
+            $v['children'] = Dever::db('goods_level_2', 'cate')->select($where);
+            $result[] = $v;
+        }
+        return $result;
+    }
+
+    public function updateManageCate($db, $data)
+    {
+        if ($data['parent']) {
+            $parent = explode(',', $data['parent']);
+            $data['top_id'] = $parent[0];
+            if (isset($parent[1])) {
+                $data['parent_id'] = $parent[1];
+            }
+        }
+        return $data;
+    }
+}

+ 69 - 0
src/cate/lib/Icon.php

@@ -0,0 +1,69 @@
+<?php namespace Cate\Lib;
+use Dever;
+class Icon
+{
+    private $token = 'Y9rt0NCy1H4LZKhxDklRks26';
+    private $cookie = 'cna=/pxEH/gQiVwCAWUeNvDgjxzu; EGG_SESS_ICONFONT=dzIFRF6UFHpWicZx2_bPclFOIt1cQpz_PZTqMLSyvEnnoZwVqWvK7ht2RRKNNSygMgEcp7bWa98XYDNW-LoTE9nMjNLdOSTa9Y6-Rn5H_k6bjWOLDvZKzgsypKSm2zK0qd29cv9I1s8YqVK5LF4J6g==; ctoken={token}; u=14130793; u.sig=PEpkMN-VcF3I7NkWH0aAoIBpIeCaAQCeG6H89fjtkgk; xlly_s=1; isg=BKioBV44WoUIjnZyvDfQlqLHeZa60QzbxRlelGLZ9CMWvUgnCuHcaz77tVVNjcSz; tfstk=fLXxt1waVz4cpbNGhiNkIfmz3cZuttI22ZSIIFYm1aQRAMuD1s4VW1QdzCDGfr5OyG_L0h4VIaeOyw1mSOIZBhs17o8g07jV0dJ_-yvTKiSq24rxizv_fg_gSTzLKJjVcmxbxgw3b6lglQ86CIObFUTycF96cCZJPhKE1q_6CuIWzH3jlhT_FUtqTcmvSmTtB1Gqp5AuiUDsCtwwMeIqsAM1endACiTRqgXJDILHZ5_u_t_lftX2aShXQgfdW1_QrjYf9HQJtsUKHwQ2fGK1kJopPtIOeI5oljtpHEdChInndiR1wTpchPlFqgLX9LfuarAMHZCe8INzzNIJoN6vNqUkS6jlhQQQrYQw616DFta7pgJAK9h_t2YpjjZ82flwG3AHndkb-EaYy3L3qbcZ_Qxy2eq82flwG3-J-u2o_fRk4';
+    private $origin = 'https://www.iconfont.cn';
+
+    # 获取图标
+    public function get($name, $method = 'find')
+    {
+        $where['search_name'] = $name;
+        $info = Dever::db('icon', 'cate')->$method($where);
+        if (!$info) {
+            $url = 'https://www.iconfont.cn/api/icon/search.json';
+            if (strstr($name, '(')) {
+                $temp = explode('(', $name);
+                $name = $temp[0];
+            }
+            $param['q'] = $name;
+            $param['sortType'] = 'updated_at';
+            $param['page'] = '1';
+            $param['pageSize'] = '20';
+            $param['fromCollection'] = '-1';
+            $param['ctoken'] = $this->token;
+            $param['t'] = time();
+            $header['cookie'] = str_replace('{token}', $this->token, $this->cookie);
+            $header['origin'] = $this->origin;
+            $data = Dever::curl($url, $param, 'post', false, $header)->result();
+            $data = Dever::json_decode($data);
+            if (isset($data['data']['icons'])) {
+                $id = false;
+                foreach ($data['data']['icons'] as $k => $v) {
+                    if (stristr($v['name'], 'logo')) {
+                        continue;
+                    }
+                    if (stristr($v['path_attributes'], 'FFFFFF')) {
+                        continue;
+                    }
+
+                    $up = $where;
+                    $up['name'] = $v['name'];
+                    $up['svg'] = $v['show_svg'];
+                    $state = Dever::db('icon', 'cate')->insert($up);
+                    if (!$id) {
+                        $id = $state;
+                    }
+                }
+                if ($method == 'find') {
+                    $info = Dever::db('icon', 'cate')->$method($id);
+                } else {
+                    $info = Dever::db('icon', 'cate')->$method($where);
+                }
+            }
+        }
+        return $info;
+    }
+
+    # 展示图标
+    public function show($id)
+    {
+        $info = Dever::db('icon', 'cate')->find($id);
+        if ($info) {
+            return $info['svg'];
+        } else {
+            return '';
+        }
+    }
+}

+ 47 - 0
src/cate/manage/core.php

@@ -0,0 +1,47 @@
+<?php
+return array
+(
+    'menu' => array
+    (
+        'cate_core' => array
+        (
+            'name' => '分类',
+            'icon' => 'barricade-line',
+            'sort' => '12',
+            'module' => 'platform',
+            'app' => 'cate',
+        ),
+
+        'cate_goods' => array
+        (
+            'parent' => 'cate_core',
+            'name' => '商品分类',
+            'icon' => 'briefcase-5-line',
+            'sort' => '1',
+        ),
+
+        'goods_level_1' => array
+        (
+            'parent'    => 'cate_goods',
+            'name'      => '一级分类',
+            'icon'      => 'luggage-cart-line',
+            'sort'      => '1',
+        ),
+
+        'goods_level_2' => array
+        (
+            'parent'    => 'cate_goods',
+            'name'      => '二级分类',
+            'icon'      => 'calendar-todo-line',
+            'sort'      => '2',
+        ),
+
+        'goods_level_3' => array
+        (
+            'parent'    => 'cate_goods',
+            'name'      => '三级分类',
+            'icon'      => 'cast-line',
+            'sort'      => '3',
+        ),
+    ),
+);

+ 52 - 0
src/cate/manage/goods_level_1.php

@@ -0,0 +1,52 @@
+<?php
+return array
+(
+    'list' => array
+    (
+        'field'      => array
+        (
+            'name',
+            'icon_id' => array
+            (
+                //'show' => '"{icon}" ? "<img src=\'{icon}\' width=\'50\' \/>" : ""',
+                'show' => 'Dever::call("cate/icon.show", "{icon_id}")',
+            ),
+            'sort' => array
+            (
+                'type' => 'input',
+                'tips' => '双击修改排序',
+            ),
+            'status' => array
+            (
+                'type' => 'switch',
+                'show'  => '{status}',
+                'active_value' => 1,
+                'inactive_value' => 2,
+            ),
+            'cdate',
+        ),
+        'button' => array
+        (
+            '新增' => 'fastadd',
+        ),
+        'data_button' => array
+        (
+            '编辑' => 'fastedit',
+        ),
+        'search'    => array
+        (
+            'name',
+            'status',
+        ),
+    ),
+    'update' => array
+    (
+        'field'    => array
+        (
+            'name' => array
+            (
+                'rules' => true,
+            ),
+        ),
+    ),
+);

+ 59 - 0
src/cate/manage/goods_level_2.php

@@ -0,0 +1,59 @@
+<?php
+return array
+(
+    'list' => array
+    (
+        'field'      => array
+        (
+            'name',
+            'parent_id',
+            'icon_id' => array
+            (
+                //'show' => '"{icon}" ? "<img src=\'{icon}\' width=\'50\' \/>" : ""',
+                'show' => 'Dever::call("cate/icon.show", "{icon_id}")',
+            ),
+            'sort' => array
+            (
+                'type' => 'input',
+                'tips' => '双击修改排序',
+            ),
+            'status' => array
+            (
+                'type' => 'switch',
+                'show'  => '{status}',
+                'active_value' => 1,
+                'inactive_value' => 2,
+            ),
+            'cdate',
+        ),
+        'button' => array
+        (
+            '新增' => 'fastadd',
+        ),
+        'data_button' => array
+        (
+            '编辑' => 'fastedit',
+        ),
+        'search'    => array
+        (
+            'name' => 'like',
+            'parent_id',
+            'status',
+        ),
+    ),
+    'update' => array
+    (
+        'field'    => array
+        (
+            'name' => array
+            (
+                'rules' => true,
+            ),
+            'parent_id' => array
+            (
+                'type' => 'select',
+            ),
+            #'desc' => 'textarea',
+        ),
+    ),
+);

+ 71 - 0
src/cate/manage/goods_level_3.php

@@ -0,0 +1,71 @@
+<?php
+return array
+(
+    'list' => array
+    (
+        'field'      => array
+        (
+            'name',
+            'top_id' => array
+            (
+                'show' => 'Dever::call("cate/goods_level_1-find", "{top_id}")["name"]',
+            ),
+            'parent_id' => array
+            (
+                'show' => 'Dever::call("cate/goods_level_2-find", "{parent_id}")["name"]',
+            ),
+            'icon_id' => array
+            (
+                //'show' => '"{icon}" ? "<img src=\'{icon}\' width=\'50\' \/>" : ""',
+                'show' => 'Dever::call("cate/icon.show", "{icon_id}")',
+            ),
+            'sort' => array
+            (
+                'type' => 'input',
+                'tips' => '双击修改排序',
+            ),
+            'status' => array
+            (
+                'type' => 'switch',
+                'show'  => '{status}',
+                'active_value' => 1,
+                'inactive_value' => 2,
+            ),
+            'cdate',
+        ),
+        'button' => array
+        (
+            '新增' => 'fastadd',
+        ),
+        'data_button' => array
+        (
+            '编辑' => 'fastedit',
+        ),
+        'search'    => array
+        (
+            'name' => 'like',
+            'parent' => array
+            (
+                'type' => 'cascader',
+                'option'    => 'Dever::call("cate/goods.getManageList")',
+            ),
+            'status',
+        ),
+    ),
+    'update' => array
+    (
+        'field'    => array
+        (
+            'name' => array
+            (
+                'rules' => true,
+            ),
+            'parent' => array
+            (
+                'type' => 'cascader',
+                'option'    => 'Dever::call("cate/goods.getManageList")',
+            ),
+        ),
+        'start' => 'cate/goods.updateManageCate',
+    ),
+);

+ 37 - 0
src/cate/table/goods_level_1.php

@@ -0,0 +1,37 @@
+<?php
+# 本来要做成一个表,后来思考很久,还是分开吧
+return array
+(
+    'name' => '商品一级分类表',
+    'order' => 'sort asc',
+    'struct' => array
+    (
+        'name' => array
+        (
+            'name'      => '分类名称',
+            'type'      => 'varchar(32)',
+        ),
+        'icon_id' => array
+        (
+            'name'      => '分类图标',
+            'type'      => 'int(11)',
+        ),
+        'status' => array
+        (
+            'name'      => '状态',
+            'type'      => 'tinyint(1)',
+            'default'   => 1,
+            'value'     => array
+            (
+                1 => '可用',
+                2 => '不可用',
+            ),
+        ),
+        'sort' => array
+        (
+            'name'      => '排序',
+            'type'      => 'int(11)',
+            'default'   => '1',
+        ),
+    ),
+);

+ 42 - 0
src/cate/table/goods_level_2.php

@@ -0,0 +1,42 @@
+<?php
+return array
+(
+    'name' => '商品二级分类表',
+    'order' => 'sort asc',
+    'struct' => array
+    (
+        'name' => array
+        (
+            'name'      => '分类名称',
+            'type'      => 'varchar(32)',
+        ),
+        'parent_id' => array
+        (
+            'name'      => '一级分类',
+            'type'      => 'int(11)',
+            'value'     => 'cate/goods_level_1',
+        ),
+        'icon_id' => array
+        (
+            'name'      => '分类图标',
+            'type'      => 'int(11)',
+        ),
+        'status' => array
+        (
+            'name'      => '状态',
+            'type'      => 'tinyint(1)',
+            'default'   => 1,
+            'value'     => array
+            (
+                1 => '可用',
+                2 => '不可用',
+            ),
+        ),
+        'sort' => array
+        (
+            'name'      => '排序',
+            'type'      => 'int(11)',
+            'default'   => '1',
+        ),
+    ),
+);

+ 51 - 0
src/cate/table/goods_level_3.php

@@ -0,0 +1,51 @@
+<?php
+return array
+(
+    'name' => '商品三级级分类表',
+    'order' => 'sort asc',
+    'struct' => array
+    (
+        'name' => array
+        (
+            'name'      => '分类名称',
+            'type'      => 'varchar(32)',
+        ),
+        'parent' => array
+        (
+            'name'      => '上级分类',
+            'type'      => 'varchar(1000)',
+        ),
+        'top_id' => array
+        (
+            'name'      => '一级分类',
+            'type'      => 'int(11)',
+        ),
+        'parent_id' => array
+        (
+            'name'      => '二级分类',
+            'type'      => 'int(11)',
+        ),
+        'icon_id' => array
+        (
+            'name'      => '分类图标',
+            'type'      => 'int(11)',
+        ),
+        'status' => array
+        (
+            'name'      => '状态',
+            'type'      => 'tinyint(1)',
+            'default'   => 1,
+            'value'     => array
+            (
+                1 => '可用',
+                2 => '不可用',
+            ),
+        ),
+        'sort' => array
+        (
+            'name'      => '排序',
+            'type'      => 'int(11)',
+            'default'   => '1',
+        ),
+    ),
+);

+ 23 - 0
src/cate/table/icon.php

@@ -0,0 +1,23 @@
+<?php
+return array
+(
+    'name' => '图标',
+    'struct' => array
+    (
+        'name' => array
+        (
+            'name'      => '图标名称',
+            'type'      => 'varchar(50)',
+        ),
+        'search_name' => array
+        (
+            'name'      => '搜索名称',
+            'type'      => 'varchar(50)',
+        ),
+        'svg' => array
+        (
+            'name'      => 'svg信息',
+            'type'      => 'text(255)',
+        ),
+    ),
+);

+ 6 - 0
src/place/api/Resource.php

@@ -40,6 +40,9 @@ class Resource extends Main
     # 点击购买按钮
     public function submit()
     {
+        if (!Place::$uid) {
+            $this->showLogin();
+        }
         $id = Dever::input('type_id', 'is_numeric', '资源ID');
         $info = $this->service->getInfo($id);
         $data['info'] = Dever::load('info', $this->service->app)->submit($info);
@@ -49,6 +52,9 @@ class Resource extends Main
     # 拉起支付
     public function pay()
     {
+        if (!Place::$uid) {
+            $this->showLogin();
+        }
         $id = Dever::input('type_id', 'is_numeric', '资源ID');
         $info = $this->service->getInfo($id);
         $info = Dever::load('info', $this->service->app)->submit($info, 'price', true);

+ 17 - 0
src/place/api/Seller.php

@@ -0,0 +1,17 @@
+<?php namespace Api\Api;
+use Dever;
+class Seller
+{
+    # 获取授权
+    public function auth()
+    {
+        $id = Dever::input('id');
+        $info = Dever::db('seller', 'place')->find($id);
+
+        if ($info['type'] == 1) {
+            # 微信小店
+            $link = Dever::url('wechat/auth.link', array('type' => 2, 'call' => 'place/seller.up'), true);
+        }
+        header('location:' . $link);
+    }
+}

+ 1 - 1
src/place/api/Url.php

@@ -11,7 +11,7 @@ class Url
         if ($info) {
             $extend = Dever::load('common', 'manage')->extend();
             $param['p'] = Place::entry($extend['info_id'], $extend['module_id'], $extend['data_id'], $id);
-            $link = Dever::url('place/data.home', $param);
+            $link = str_replace('https://center.yuandaibao.com/src/place/', 'https://place.work.yuandaibao.com/', Dever::url('place/data.home', $param));
             header('HTTP/1.1 301 Moved Permanently');
             header('Location: ' . $link);
         }

+ 47 - 0
src/place/manage/seller.php

@@ -0,0 +1,47 @@
+<?php
+return array
+(
+    'list' => array
+    (
+        'field'      => array
+        (
+            'name',
+            'type',
+            'sort',
+            'status',
+            'cdate',
+        ),
+        'button' => array
+        (
+            '新增' => array('fastadd'),
+        ),
+        'data_button' => array
+        (
+            '编辑' => 'fastedit',
+            # 微信授权,
+            '授权' => array('link', Dever::url('wechat/auth.link', array('type' => 1), true)),
+        ),
+        'search'    => array
+        (
+            'name',
+            'type',
+            'status',
+        ),
+    ),
+    'update' => array
+    (
+        'field'    => array
+        (
+            'name' => array
+            (
+                'rules' => true,
+            ),
+            'type' => array
+            (
+                'type' => 'radio',
+                'rules' => true,
+            ),
+            'sort',
+        ),
+    ),
+);

+ 1 - 1
src/resource/content/lib/Info.php

@@ -27,7 +27,7 @@ class Info
             }
         }
         if ($result['status'] == 1) {
-            if ($id) {
+            if (isset($id)) {
                 $result['value'] = Dever::db('value', 'content')->find(array('info_id' => $info['id'], 'id' => $id));
             } else {
                 $result['value'] = Dever::db('value', 'content')->select(array('info_id' => $info['id']));

+ 3 - 3
src/resource/goods/lib/Express.php

@@ -76,9 +76,9 @@ class Express
     {
         $param['number'] = $number;
         $param['mobile'] = substr($mobile, -4);
-        //$data = Dever::load('account', 'api')->run('aliyun_market', 'express', $param);
-        $data['data']['list'] = array();
-        $data['data']['state'] = 2;
+        $data = Dever::load('account', 'api')->run('aliyun_market', 'express', $param);
+        #$data['data']['list'] = array();
+        #$data['data']['state'] = 2;
         if ($data && isset($data['data']['list'])) {
             if ($data['data']['state'] == 3) {
                 $param['status'] = 1;

+ 1 - 1
src/resource/goods/lib/Order.php

@@ -291,7 +291,7 @@ class Order
                     $v['name'] .= ' 已发货:' . $page->info['express']['name'] . ',' . $page->info['express']['number'];
                 }
             } elseif ($k == 4) {
-                if (isset($page->info['express']['log'])) {
+                if (isset($page->info['express']['log'][0])) {
                     $v['name'] .= ' ' . $page->info['express']['log'][0]['status'];
                 }
             } elseif ($k == 5 && $page->info['status'] > 6) {

+ 54 - 0
src/wechat/api/Auth.php

@@ -0,0 +1,54 @@
+<?php namespace Wechat\Api;
+use Dever;
+use Dever\Helper\Secure;
+use Manage\Lib\Auth as Core;
+class Auth extends Core
+{
+    public function __construct()
+    {
+        $this->account = 'wechat_open';
+        $this->api = Dever::load('account', 'api')->run($this->account, 'msg', array(), 1, 'setting');
+        $extend = Dever::load('common', 'manage')->extend();
+        if (!$extend) {
+            Dever::error('身份不存在');
+        }
+        $this->info = Dever::db('info', 'place')->find(array('id' => $extend['data_id']));
+        if (!$this->info) {
+            Dever::error('身份不存在');
+        }
+        $this->env = Dever::input('env', 'is_numeric', '环境', 6);
+    }
+
+    public function link()
+    {
+        $param['component_appid'] = $this->api->field->appid;
+        $param['pre_auth_code'] = Dever::load('info', 'wechat')->getPreAuthCode();
+        $param['redirect_uri'] = Dever::url('wechat/auth.code', array(), true);
+        /**
+         * - 1 表示手机端仅展示公众号;2 表示仅展示小程序,3 表示公众号和小程序都展示。
+- 4表示小程序推客账号;
+- 5表示视频号账号;
+- 6表示全部,即公众号、小程序、视频号都展示
+         */
+        $param['auth_type'] = Dever::input('type');
+        Dever::load('account', 'api')->run($this->account, 'auth_link', $param, $this->env, 'jump');
+    }
+
+    public function code()
+    {
+        $auth_code = Dever::input('auth_code');
+        $expires_in = Dever::input('expires_in');
+
+        Dever::load('info', 'wechat')->up(false, 'auth_code', $auth_code, $expires_in, $this->info['id']);
+
+        $param['auth_code'] = $auth_code;
+        $param['component_access_token'] = Dever::load('info', 'wechat')->getAccessToken();
+        $data = Dever::load('account', 'api')->run($this->account, 'auth_token', $param);
+        if (isset($data['authorization_info'])) {
+            $data = $data['authorization_info'];
+            Dever::load('auth', 'wechat')->up(false, $this->info['id'], $data['authorizer_access_token'], $data['authorizer_refresh_token'], $data['expires_in'], $data['authorizer_appid'], $data['func_info']);
+            echo '授权成功';die;
+        }
+        echo '授权失败';die;
+    }
+}

+ 72 - 0
src/wechat/api/Oauth.php

@@ -0,0 +1,72 @@
+<?php namespace Wechat\Api;
+use Dever;
+use Dever\Helper\Secure;
+class Oauth
+{
+    public function __construct()
+    {
+        $this->t = Dever::input('t', 'is_string', 't');
+        $this->account = Dever::input('account', 'is_string', '通信账户');
+    }
+
+    # 获取code
+    public function code()
+    {
+        $refer = Dever::input('refer');
+        $scope = Dever::input('scope', 'is_string', 'scope', 'snsapi_base');
+        $param['scope'] = $scope;
+        $param['redirect_uri'] = urlencode(Dever::url('api/oauth.token', array
+            (
+                't' => $this->t,
+                'account' => $this->account,
+                'refer' => Secure::encode($refer),
+            )
+        ));
+        Dever::load('account', 'api')->run($this->account, 'oauth_code', $param, 1, 'jump');
+    }
+
+    # 获取token
+    public function token()
+    {
+        $param['code'] = Dever::input('code', 'is_string', 'code');
+        $data = Dever::load('account', 'api')->run($this->account, 'oauth_token', $param);
+        if ($data && isset($data['openid'])) {
+            if ($t = Secure::checkLogin($this->t)) {
+                if ($t['uid'] && $t['uid'] > 0) {
+                    $update['uid'] = $t['uid'];
+                    $update['account_id'] = $data['account_id'];
+                    $update['env'] = 3;
+                    $info = Dever::db('openid', 'api')->find($update);
+                    if (!$info) {
+                        $update['openid'] = $data['openid'];
+                        Dever::db('openid', 'api')->insert($update);
+                    }
+                }
+            }
+            if (isset($data['scope']) && $data['scope'] == 'snsapi_userinfo') {
+                $user = $this->user($data);
+            }
+        }
+        $refer = Secure::decode(Dever::input('refer'));
+        if ($refer) {
+            header('location:' . $refer);
+        }
+    }
+
+    # 获取用户信息
+    public function user($data)
+    {
+        $param['access_token'] = $data['access_token'];
+        $param['openid'] = $data['openid'];
+        $data = Dever::load('account', 'api')->run($this->account, 'oauth_user', $param);
+        if ($data) {
+            # 获取到用户了
+        }
+    }
+
+    # 根据refresh_token获取token
+    public function refreshToken($id)
+    {
+
+    }
+}

+ 92 - 5
src/wechat/api/Receive.php

@@ -1,5 +1,6 @@
 <?php namespace Wechat\Api;
 use Dever;
+use Api\Lib\Platform\Request;
 class Receive
 {
     # 获取消息
@@ -9,24 +10,61 @@ class Receive
         $input['body'] = file_get_contents('php://input', 'r');
         $this->log($input);
 
+        $test = Dever::input('test');
+        if ($test == 1) {
+            $input = '{"l":"receive.callback","m":"auth","signature":"60e9631eb2b17edbbe1805dc20733ddd9c29d238","timestamp":"1724457958","nonce":"942288454","encrypt_type":"aes","msg_signature":"fbaf4080e53d54253cd898644f56535b3e81e64f","body":"<xml>\n    <AppId><![CDATA[wxa787f5f39aa0598c]]></AppId>\n    <Encrypt><![CDATA[289f2UFxfqOMRCkY6dF4L7b0RuTcVxcKGVEZU3nhJHuTlgA2uvDrTV5YhppDyoJYGIFf2KenpUB4Xg+1wYefxLnYGV8UyJMVZIzlLyPFWMgV8Jw+ElwN2vogPvJ+ceXwDdpzPcLuf7h9MPoedlQqh9Kv0wjjJ6wX8M9i4GZQjYhKWWCcj6hgyymt4eTPJmJ4cYh+X4a2v883Srt581uQSOa+lAv8jbvtYRVk/23qRn5FsOSeIzzGgoj0o4VGZx/muOl0kMQI8B5lZDKCtCeSljWj14c6UQ/5OQh2M22LYLi3PcE3zcoDa5cOni5adUPQQX5sWoAsRBj9U6K+idvG88XLLutA/kM4F+MaX1lcBMhq49DTN2I3qZRzddPdutZi70E/+A7ou9zzZUArgDuuCz35P40/BFGoS8dh9rGXvDfnYlS549XJ0J4fJ14X12q7LImBvr61ugNKFTMGJapgJg==]]></Encrypt>\n</xml>\n"}';
+            $input = Dever::json_decode($input);
+        }
+        $input['body'] = (array) simplexml_load_string($input['body'], null, LIBXML_NOCDATA);
+        $input = array_merge($input, $input['body']);
+        $api = Dever::load('account', 'api')->run('wechat_open', 'msg', $input, 1, 'setting');
+        $request = new Request($api->field, $api->platform['id'], $api->type, $api->info['id']);
+        $body = $request->body();
+        if ($body['sign'] != $input['msg_signature']) {
+            Dever::error('签名验证失败');
+        }
+        #$input['Encrypt'] = base64_decode($input['Encrypt']);
+        $api->field->key = base64_decode($api->field->key . '=');
+        $iv = substr($api->field->key, 0, 16);     
+
+        $input['Encrypt'] = str_replace(' ', '+', $input['Encrypt']);
+
+        $body = openssl_decrypt($input['Encrypt'], 'AES-256-CBC', substr($api->field->key, 0, 32), OPENSSL_ZERO_PADDING, $iv);
+        $pkc_encoder = new PKCS7Encoder;
+        $body = $pkc_encoder->decode($body);
+
+        if (strlen($body) < 16)
+            Dever::error('解密失败');
+
+        $body = substr($body, 16, strlen($body));
+        $len_list = unpack("N", substr($body, 0, 4));
+        $xml_len = $len_list[1];
+        $xml_content = substr($body, 4, $xml_len);
+        $appid = substr($body, $xml_len + 4);
+        if ($appid != $api->field->appid) {
+            Dever::error('第三方平台配置错误');
+        }
+        $body = (array) simplexml_load_string($xml_content, null, LIBXML_NOCDATA);
         $m = $input['m'];
         if ($m == 'auth') {
             # 权限
-            $this->auth();
+            $this->auth($body);
         } else {
-            $this->msg($m);
+            $this->msg($m, $body);
         }
         echo 'success';die;
     }
 
     # 获取权限信息
-    private function auth()
+    private function auth($body)
     {
-        
+        if (isset($body['ComponentVerifyTicket'])) {
+            Dever::load('info', 'wechat')->up(false, 'component_verify_ticket', $body['ComponentVerifyTicket'], 12*3600);
+        }
     }
 
     # 获取消息
-    private function msg($m)
+    private function msg($m, $body)
     {
         list($method, $appid) = explode('/', $m);
     }
@@ -36,4 +74,53 @@ class Receive
     {
         return Dever::log($log, 'wechat');
     }
+}
+
+/**
+ * PKCS7Encoder class
+ *
+ * 提供基于PKCS7算法的加解密接口.
+ */
+class PKCS7Encoder
+{
+    public static $block_size = 32;
+
+    /**
+     * 对需要加密的明文进行填充补位
+     * @param $text 需要进行填充补位操作的明文
+     * @return 补齐明文字符串
+     */
+    function encode($text)
+    {
+        $block_size = PKCS7Encoder::$block_size;
+        $text_length = strlen($text);
+        //计算需要填充的位数
+        $amount_to_pad = PKCS7Encoder::$block_size - ($text_length % PKCS7Encoder::$block_size);
+        if ($amount_to_pad == 0) {
+            $amount_to_pad = PKCS7Encoder::block_size;
+        }
+        //获得补位所用的字符
+        $pad_chr = chr($amount_to_pad);
+        $tmp = "";
+        for ($index = 0; $index < $amount_to_pad; $index++) {
+            $tmp .= $pad_chr;
+        }
+        return $text . $tmp;
+    }
+
+    /**
+     * 对解密后的明文进行补位删除
+     * @param decrypted 解密后的明文
+     * @return 删除填充补位后的明文
+     */
+    function decode($text)
+    {
+
+        $pad = ord(substr($text, -1));
+        if ($pad < 1 || $pad > 32) {
+            $pad = 0;
+        }
+        return substr($text, 0, (strlen($text) - $pad));
+    }
+
 }

+ 20 - 0
src/wechat/api/Test.php

@@ -0,0 +1,20 @@
+<?php namespace Wechat\Api;
+use Dever;
+class Test
+{
+    # 获取消息
+    public function getToken()
+    {
+        $token = Dever::load('info', 'wechat')->getAccessToken();
+
+        print_r($token);die;
+    }
+
+    # 获取消息
+    public function getPreAuthCode()
+    {
+        $token = Dever::load('info', 'wechat')->getPreAuthCode();
+
+        print_r($token);die;
+    }
+}

+ 51 - 0
src/wechat/lib/Auth.php

@@ -0,0 +1,51 @@
+<?php namespace Wechat\Lib;
+use Dever;
+class Auth
+{
+    # 获取数据
+    public function get($place_id)
+    {
+        $info = Dever::db('auth', 'wechat')->find(array('place_id' => $place_id));
+        if ($info) {
+            if (time() >= $info['expires']) {
+                # 需要重新获取最新的信息
+                $param['component_access_token'] = Dever::load('info', 'wechat')->getAccessToken();
+                $param['authorizer_appid'] = $info['appid'];
+                $param['authorizer_refresh_token'] = $info['refresh_token'];
+                $data = Dever::load('account', 'api')->run($this->account, 'auth_refresh_token', $param);
+                if (isset($data['authorizer_access_token'])) {
+                    return $this->up($info['id'], $info['place_id'], $data['authorizer_access_token'], $data['authorizer_refresh_token'], $data['expires_in']);
+                }
+                Dever::error('系统错误');
+            }
+            return $info['access_token'];
+        }
+    }
+
+    # 更新数据
+    public function up($id, $place_id, $access_token, $refresh_token, $expires, $appid = false, $func_info = false)
+    {
+        if (!$id) {
+            $data['place_id'] = $place_id;
+            $info = Dever::db('auth', 'wechat')->find($data);
+            if ($info) {
+                $id = $info['id'];
+            }
+        }
+        $data['access_token'] = $access_token;
+        $data['refresh_token'] = $refresh_token;
+        $data['expires'] = $expires - 60 + time();
+        if ($appid) {
+            $data['appid'] = $appid;
+        }
+        if ($func_info) {
+            $data['func_info'] = Dever::json_encode($func_info);
+        }
+        if ($id) {
+            Dever::db('auth', 'wechat')->update($id, $data);
+        } else {
+            Dever::db('auth', 'wechat')->insert($data);
+        }
+        return $access_token;
+    }
+}

+ 73 - 0
src/wechat/lib/Info.php

@@ -0,0 +1,73 @@
+<?php namespace Wechat\Lib;
+use Dever;
+class Info
+{
+    # 获取accesstoken
+    public function getAccessToken()
+    {
+        $call = function() {
+            $param['component_verify_ticket'] = $this->get('component_verify_ticket');
+            $data = Dever::load('account', 'api')->run('wechat_open', 'token', $param);
+            if (isset($data['component_access_token'])) {
+                return array($data['component_access_token'], $data['expires_in']);
+            }
+            Dever::error('系统错误');
+        };
+        return $this->get('component_access_token', $call);
+    }
+
+    # 获取预授权码
+    public function getPreAuthCode()
+    {
+        $call = function() {
+            $param['component_access_token'] = $this->getAccessToken();
+            $data = Dever::load('account', 'api')->run('wechat_open', 'pre_auth_code', $param);
+            if (isset($data['pre_auth_code'])) {
+                return array($data['pre_auth_code'], $data['expires_in']);
+            }
+            Dever::error('系统错误');
+        };
+        return $this->get('pre_auth_code', $call);
+    }
+
+    # 获取某个有效的信息数据
+    public function get($key, $call = false)
+    {
+        $info = Dever::db('info', 'wechat')->find(array('key' => $key));
+        if ($info) {
+            if (time() >= $info['expires']) {
+                # 需要重新获取最新的信息
+                if ($call) {
+                    list($value, $expires) = $call();
+                    return $this->up($info['id'], $key, $value, $expires);
+                }
+            }
+            return $info['value'];
+        }
+        if ($call) {
+            list($value, $expires) = $call();
+            return $this->up(false, $key, $value, $expires);
+        }
+    }
+
+    # 更新某个信息数据
+    public function up($id, $key, $value, $expires, $place_id = -1)
+    {
+        $data['key'] = $key;
+        $data['place_id'] = $place_id;
+        if (!$id) {
+            $info = Dever::db('info', 'wechat')->find($data);
+            if ($info) {
+                $id = $info['id'];
+            }
+        }
+        $data['value'] = $value;
+        $data['expires'] = $expires - 60 + time();
+        if ($id) {
+            Dever::db('info', 'wechat')->update($id, $data);
+        } else {
+            Dever::db('info', 'wechat')->insert($data);
+        }
+        return $value;
+    }
+}

+ 1 - 47
src/wechat/manage/core.php

@@ -3,52 +3,6 @@ return array
 (
     'menu' => array
     (
-        'info' => array
-        (
-            'parent'    => 'platform',
-            'name'      => '领域管理',
-            'icon'      => 'archive-drawer-line',
-            'sort'      => '5',
-        ),
-
-        'money' => array
-        (
-            'parent'    => 'platform',
-            'name'      => '货币管理',
-            'icon'      => 'money-cny-box-line',
-            'sort'      => '6',
-        ),
-
-        'express' => array
-        (
-            'parent'    => 'platform',
-            'name'      => '快递管理',
-            'icon'      => 'exchange-funds-fill',
-            'sort'      => '7',
-        ),
-
-        'sector_manage' => array
-        (
-            'parent'    => 'sector',
-            'name'      => '领域管理',
-            'icon'      => 'group-2-line',
-            'sort'      => '100',
-        ),
-
-        'user' => array
-        (
-            'parent'    => 'sector_manage',
-            'name'      => '用户管理',
-            'icon'      => 'user-settings-line',
-            'sort'      => '1',
-        ),
-
-        'role' => array
-        (
-            'parent'    => 'sector_manage',
-            'name'      => '角色管理',
-            'icon'      => 'archive-line',
-            'sort'      => '2',
-        ),
+        
     ),
 );

+ 40 - 0
src/wechat/table/auth.php

@@ -0,0 +1,40 @@
+<?php
+return array
+(
+    'name' => '微信开发平台商户信息',
+    'partition' => 'Dever::call("manage/common.system", array(false, false))',
+    'struct' => array
+    (
+        'place_id' => array
+        (
+            'name'      => '身份',
+            'type'      => 'int(11)',
+            'default'   => -1,
+        ),
+        'appid' => array
+        (
+            'name'      => 'appid',
+            'type'      => 'varchar(32)',
+        ),
+        'access_token' => array
+        (
+            'name'      => 'access_token',
+            'type'      => 'varchar(100)',
+        ),
+        'refresh_token' => array
+        (
+            'name'      => 'refresh_token',
+            'type'      => 'varchar(100)',
+        ),
+        'expires' => array
+        (
+            'name'      => '过期时间',
+            'type'      => 'int(11)',
+        ),
+        'func_info' => array
+        (
+            'name'      => '授权信息',
+            'type'      => 'varchar(2000)',
+        ),
+    ),
+);

+ 13 - 34
src/wechat/table/info.php

@@ -1,50 +1,29 @@
 <?php
 return array
 (
-    'name' => '领域',
-    'order' => 'sort asc',
+    'name' => '微信开发平台存储信息',
     'struct' => array
     (
-        'name' => array
+        'key' => array
         (
-            'name'      => '领域名称',
-            'type'      => 'varchar(200)',
-        ),
-        'number' => array
-        (
-            'name'      => '领域号',
-            'type'      => 'varchar(60)',
+            'name'      => '信息标识',
+            'type'      => 'varchar(100)',
         ),
-        'mobile' => array
+        'value' => array
         (
-            'name'      => '手机号',
-            'type'      => 'varchar(11)',
+            'name'      => '信息值',
+            'type'      => 'varchar(200)',
         ),
-        'sort' => array
+        'expires' => array
         (
-            'name'      => '排序',
+            'name'      => '过期时间',
             'type'      => 'int(11)',
-            'default'   => '1',
         ),
-        'status' => array
+        'place_id' => array
         (
-            'name'      => '状态',
-            'type'      => 'tinyint(1)',
-            'default'   => 1,
-            'value'     => array
-            (
-                1 => '启用',
-                2 => '关闭',
-            ),
-        ),
-    ),
-    'default' => array
-    (
-        'field' => 'name,number,sort,cdate',
-        'value' => array
-        (
-            '"默认领域","default",-100,' . DEVER_TIME,
+            'name'      => '身份',
+            'type'      => 'int(11)',
+            'default'   => -1,
         ),
-        'num' => 1,
     ),
 );