12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php namespace Api\Lib;
- use Dever;
- class Util
- {
- # 生成订单号
- public function createNumber($prefix, $table, $where = array())
- {
- $number = \Dever\Helper\Str::order($prefix);
- $where['order_num'] = $number;
- $state = Dever::db($table)->find($where);
- if (!$state) {
- return $number;
- } else {
- return $this->createNumber($prefix, $table, $where);
- }
- }
- # 获取openid 仅jspai和小程序需要openid
- public function openid($account, $env, $uid, $result = array())
- {
- $account = Dever::db('account', 'api')->find(array('key' => $account));
- if ($account) {
- $info = Dever::db('openid', 'api')->find(array('account_id' => $account['id'], 'uid' => $uid, 'env' => $env));
- if ($info) {
- $result['openid'] = $info['openid'];
- } else {
- if ($env == 3) {
- # jsapi 一般需要oauth授权
- if (empty($result['t'])) {
- $result['t'] = \Dever\Helper\Secure::login($uid);
- }
- $result['account'] = $account['key'];
- $result['link'] = Dever::url('api/oauth.code', $result);
- } elseif ($env == 5) {
- # 小程序
- $param['js_code'] = Dever::input('applet_code', 'is_string', '登录信息');
- $data = Dever::load('account', 'api')->run($account, 'applet_login', $param, $env);
- if (isset($data['openid'])) {
- $result['openid'] = $data['openid'];
- $update['uid'] = $uid;
- $update['account_id'] = $account['id'];
- $update['env'] = $env;
- $update['openid'] = $data['openid'];
- Dever::db('openid', 'api')->insert($update);
- }
- }
- }
- }
- return $result;
- }
- # 获取参数类型
- public function fieldType($platform_id)
- {
- $data = array();
- $data[] = array
- (
- 'id' => 1,
- 'name' => '格式转换',
- 'children' => Dever::db('format', 'api')->select([]),
- );
- $where = ['platform_id' => $platform_id];
- $data[] = array
- (
- 'id' => 2,
- 'name' => '加密',
- 'children' => Dever::db('platform_ssl', 'api')->select($where),
- );
- $data[] = array
- (
- 'id' => 3,
- 'name' => '签名',
- 'children' => Dever::db('platform_sign', 'api')->select($where),
- );
- return $data;
- }
- # 获取签名列表
- public function getPlatformSign($platform_id)
- {
- return Dever::db('platform_sign', 'api')->select(array('platform_id' => $platform_id));
- }
- # 格式转换
- public function format($id, $value)
- {
- $info = Dever::db('format', 'api')->find($id);
- if ($info) {
- $info['method'] = str_replace('{value}', "'{value}'", $info['method']);
- $value = \Dever\Helper\Str::val($info['method'], array('value' => $value));
- }
- return $value;
- }
- }
|