Opencart &Bootstrap&Android&IOS&JsonRPC&微信公众平台

OPENCART

OpenCart是开源、简洁、易用、功能丰富、SEO最佳优化的B2B, B2C解决方案。尝试着使用了Magento ,ecshop ....不少,opencart 比较出众。php

BOOTSTRAPjson

BootStrap已经成为解决移动互联网网站的前段利器,让opencart穿上bootstrap的外衣,让你的电商平台自适应移动终端的访问。bootstrap

解决方案:http://www.opencart.com/index.php?route=extension/extension/info&extension_id=10498微信

OPENCART JSONRPC

为ANDROID 和 IOS 提供JSONRPC 服务,下列是一个简单的PHP实现。微信公众平台

在OPENCART的路径   opencart\catalog\controller 路径下建立目录service,并建立jsonRPC.php优化

<?php 
class ControllerServiceJsonRPC extends Controller {

	public function index() {
		//获取客户端 JSON 请求
		$request_json_str = $GLOBALS['HTTP_RAW_POST_DATA'];
		//获得JSONRPC 请求对象
		$jsondecode = json_decode($request_json_str);
		//验证请求的method是否合法
		if ($jsondecode->method  && $this->validation($jsondecode->method)) {
			eval('$this->'.$jsondecode->method.'($jsondecode);');
		}
	}
	
	/**
	 * 公共方法 建立JSON RPC 响应对象
	 */
	private function createJSONObject($error_code, $error_msg, $obj) {
		$jsonResponseArray = array();
		$jsonResponseArray['id'] = "1";
		$jsonResponseArray['result'] = array(
			"errorMessage"=>$error_msg,
			"errorCode"=>$error_code,
			"response"=>$obj);
		return json_encode($jsonResponseArray);
	}
	
	/**
	 * 得到商品分类
	 * $reqParams[0] = 父分类ID
	 * 请求JSON样例 {"id":"4","jsonrpc":"2.0","method":"getCategory","params":["18"]}
	 */
	private function getCategory($jsondecode) {
		$this->load->model('catalog/category');	
		$reqParams = $jsondecode->params;
		$category_info = $this->model_catalog_category->getCategory($reqParams[0]);
		echo $this->createJSONObject("0000", "ok", $category_info);
	}
	
	private function validation($methodName) {
		$methodArray = array();
		$methodArray[] = "getCategory";
		$methodArray[] = "getProduct";
		if (in_array($methodName, $methodArray)) {
			return true;
		} else {
			return false;
		}
	}
}
?>

支持opencart JSONRPC的方法网站


获取分类

方法名称:getCategory
this

方法参数:分类ID
url

返回值:分类列表JSONspa

获取单个商品明细

方法名称:getProduct

方法参数:商品ID

返回值:商品明细:{options[], recomment[] .....}

商品检索

用户注册

用户登陆

找回密码

订单历史

订单查询

商品收藏

购物车


ANDROID

IOS

微信公众平台

相关文章
相关标签/搜索