8 Star 13 Fork 5

XpmJS / xapp

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
contribute
Sync branch
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README
MIT

XpmJS - 云端应用 Demo

一、为啥需要云端应用

对于一些特定的业务需求,比如需要与现有系统对接,再比如需要查询各种外部 API 接口,需要实现各类的鉴权算法。对于一些机密数据,比如API的 Secret KEY,需要保存在云端。对于这部分需求,可以通过编写 XpmJS 云端应用来实现。

XpmJS 将逐步提供各类云端应用,满足大家需要

二、本示例实现了一个火车票余票查询的接口

1. 调用方法 ( @小程序 )

var xapp = app.xpm.require('App', 'xapp' );

 xapp.api( 'ticket', 'available' )

 .post({
    'train_date':'2017-01-26',
    'from_station':'BJP',
    'to_station':'SHH'
})

.then( function( resp ) {
  console.log('POST RESP:', resp );
})

.catch( function( excp ) {
  console.log('POST EXCP:', excp );
});

2. 云端程序安装

下载代码 下载本项目代码,放置在云端服务器 /host/apps/ 目录下 ( 对应容器中的目录 /apps )。

安装应用 登录管理菜单,从左侧菜单,进入应用管理,点击扫描应用; 在应用列表中找到应用,点击安装。安装成功后,左侧菜单会出现对应菜单。

应用安装

3. API 接口申请

https://www.juhe.cn/docs/api/id/173/aid/580

三、云端应用开发简明教程

XmlJS 云端程序基于团队猫系统开发,团队猫自带应用引擎、MVC框架,所以通过制作团队猫应用即可。团队猫应用引擎,除了可以实现 XpmJS 云端应用接口之外,也可以用来实现各种系统的后台。具体请参考相关文档( tuanduimao.com )

第一步:登录云主机,初始化团队猫应用

sudo docker exec -it xpmjs-server /bin/bash   # 切换到容器 shell 环境
mkdir -p /apps/myapp
cd /apps/myapp   # 进入应用目录
tdm app init   # 初始化,生成 MVC 框架,程序配置文件等
exit; #退出容器

第二步:安装应用

登录管理菜单,从左侧菜单,进入应用管理,点击扫描应用; 在应用列表中找到应用,点击安装。安装成功后,左侧菜单会出现对应菜单。

应用安装

第三步: 编写接口

创建控制器 vi /host/apps/myapp/controller/Ticket.php

<?php
use \Tuanduimao\Loader\App as App;
use \Tuanduimao\Utils as Utils;
use \Tuanduimao\Tuan as Tuan;
use \Tuanduimao\Excp as Excp;
use \Tuanduimao\Conf as Conf;


class TicketController extends \Tuanduimao\Loader\Controller {
	
	function __construct() {
	}

	/**
	 * 查询余票
	 *
	 * 
	 * @return [type] [description]
	 */
	function available() {

		// 只有登录用户可以查询
		if ( $_SESSION['_group'] != 'member' ) {
			throw new Excp("没有查询权限", 500, ['group'=>$_SESSION['_group'], 'should be'=>'member']);
		}

		$data = $_POST;
		$data['train_date'] = !empty($data['train_date']) ? $data['train_date'] : date("Y-m-d");
		$data['from_station'] = !empty($data['from_station']) ? $data['from_station'] :'BJP';
		$data['to_station'] = !empty($data['to_station']) ? $data['to_station'] :'SHH';

		// 聚合数据申请
		// @see https://www.juhe.cn/docs/api/id/173/aid/580
		$data['key'] = '去聚合数据申请';
		$api = "http://op.juhe.cn/trainTickets/ticketsAvailable";
		
		$resp = Utils::Request('POST', $api, ["data"=>$data]);

		Utils::out($resp);

	}

}
The MIT License (MIT) Copyright (c) 2016 xpmjs.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. https://www.xpmjs.com

About

XpmJS 云端应用 Demo expand collapse
PHP
MIT
Cancel

Releases

No release

Contributors

All

Activities

Load More
can not load any more
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/xpmjs/xapp.git
git@gitee.com:xpmjs/xapp.git
xpmjs
xapp
xapp
master

Search

344bd9b3 5694891 D2dac590 5694891