管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。% M: M5 F, A \5 {) r
1.添加商品信息- ]7 O8 Z/ B# `: L* g Z9 q
2.添加图片
* C/ o& s1 Z% Z+ t1 B" C3.查询所有产品
# L! e8 ]: v R s4.查询某个具体产品信息
' o3 R' l2 M( N3 c( i5.删除某个产品* N6 W( F% p& Y$ Z* X5 }
6.删除图片
. i9 c- B* A: n9 g0 [6 Q7.图像识别
+ D+ u. }, Z) O, o) q% y F, c5 ~4 X! \2 n G6 d
图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey; c7 a7 l& r$ ?9 ~! r, y
! ?6 E) F. ^0 p' W! ]$ T1 s
PHP示例:
8 J5 d1 R. X* d- K( Z- <!--?php
% P9 U+ N: N/ a# L" h" P - // +----------------------------------------------------------------------
, r$ _4 c3 R$ j" K' D - // | JuhePHP [ NO ZUO NO DIE ]& b% O( g! Z6 A! Y3 Z4 ~* D7 }
- // +----------------------------------------------------------------------
1 N3 z$ x8 H5 [4 I' Q4 [: u. k6 ? - // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.
( K; T4 T2 Z6 K0 e - // +----------------------------------------------------------------------
( q- z, M6 Q1 q" O l - // | Author: Juhedata <info@juhe.cn-->& E: B; s4 b! |! Q. R
- // +----------------------------------------------------------------------
* [9 g2 t& l* j/ M -
/ u- e1 M0 X$ B - //----------------------------------; B* R, ]0 e) I/ F8 o" H
- // 图像识别调用示例代码 - 聚合数据
9 S2 k# f8 b/ ^# P* W7 ]. @& Y - // 在线接口文档:http://www.juhe.cn/docs/117" t5 C" O; Z* C
- //----------------------------------
4 R" Y; M( o; j# B& R - . N5 I( ^/ ?1 D+ ]) Z
- header('Content-type:text/html;charset=utf-8');( j8 W' P* h7 E. e% ?
- 7 J; s2 G m& T5 T6 `
-
6 o. U9 r# u9 [* |! G1 h# z! r - //配置您申请的appkey$ G: g% a4 |# J+ e- B9 ]
- $appkey = "*********************";
; P7 D6 C4 p& x7 [# s& R -
" |, ?' V' _! Q0 o; t. d% [6 v; }, z -
2 s/ c k- g) i5 y$ Y - 4 O p5 } F& @* Q
- a) ?8 r/ y! i2 \8 H6 y
- //************1.图像上传************, l2 i$ R% R* u% q- B3 r& s
- $url = "http://japi.juhe.cn/image_recognition/upload";; _1 ]- v% w }) f
- $params = array(
2 ]/ E i. F- Z5 E) W, K* j2 q2 y - "file" => "",//上传的单张图片+ P, B! W* x( k, O3 c: K# L
- "key" => $appkey,//APP Key
- }7 H- S5 Z6 t a+ [; d, ]6 n - "pname" => "",//包名' p( O3 f2 I4 Q/ P; s
- );3 }1 u, f6 Z, z3 o
- $paramstring = http_build_query($params);
: M- h% P6 `8 ~) K( h: s$ D q - $content = juhecurl($url,$paramstring,1);
% K6 R8 q: w" y# a2 ^5 C - $result = json_decode($content,true);
( {& v7 I& \8 B* l - if($result){8 Q, y4 a# e( a2 G
- if($result['error_code']=='0'){4 X ^# o# o) |9 {' Z* Z
- print_r($result);
8 P m: g' M% ~ - }else{
: I7 Z2 G4 T" A, g, } - echo $result['error_code'].":".$result['reason'];
" u& l9 ?3 y3 c# q$ Q0 N - }! C/ P9 C. t9 `+ k8 G
- }else{
1 q$ K2 `' i5 m( o: Z. h - echo "请求失败";& z5 ]. u9 c" J- x+ `( D9 Q
- }
* K$ J5 m) Q y/ h1 d. c - //**************************************************
+ s+ e5 u. l- D. e' z. D, v9 X - : o- R3 a& d5 o! W$ @
- 4 m1 j2 r- x) J" c3 x- H
- $ R* d. c8 T! L( e/ b
- - V3 T" W/ T3 h- E
- //************2.查寻上传图像信息************" A( p$ u2 U- o# f
- $url = "http://japi.juhe.cn/image_recognition/findAll";
4 U' l8 Z' n- s9 D3 {! } - $params = array(
( T6 U( t2 l1 U* O+ [ - "key" => $appkey,//APP Key
* ]4 D/ a0 k' ]: j; o6 u - );+ S/ K2 J. G0 [3 N( j
- $paramstring = http_build_query($params);+ D: h" ~# k6 L- C& h/ g
- $content = juhecurl($url,$paramstring);
6 c, \- b7 S/ ^: |0 q - $result = json_decode($content,true);/ P2 o% s) S5 R5 O! G
- if($result){/ c" L( \& I0 L$ n+ l
- if($result['error_code']=='0'){
* o" @; F' h! B9 b - print_r($result);( S5 j; R8 ?. ~8 N! W
- }else{0 I3 i3 W# y/ A+ h% X
- echo $result['error_code'].":".$result['reason'];% K0 D+ c! t! r4 }
- }
, r5 s1 h, `1 [# ?% q3 h - }else{
% T8 q: g) P1 F* J6 F* I - echo "请求失败";
8 V6 v0 d% C% R8 C# W1 M1 U - }
0 u' ~7 _& R; h2 D - //**************************************************+ w# T/ n8 k- f+ b5 z
-
$ E# S2 [7 i n* D% @2 t. ` -
# d" q! R8 j) H# [ -
0 h! B! g; u+ w, U8 i/ b - ( f5 [& K# k$ Z' {" R6 X) `- m
- //************3.删除图像信息************( C+ h* j J7 Q; l4 n1 v
- $url = "http://japi.juhe.cn/image_recognition/delete";# s1 i4 |6 Q: S" Q
- $params = array(& U- u- H5 v/ I& }/ Q0 D
- "key" => $appkey,//APP Key6 @+ i8 V9 |, W$ @* B" `
- "imageId" => "",//图片ID
{! s3 O7 s( u" I - );
/ Z; B- B, \9 O - $paramstring = http_build_query($params);
j% e. t. s9 s$ ~ - $content = juhecurl($url,$paramstring);3 m/ w6 J* C$ o- h, }1 a! S
- $result = json_decode($content,true);9 l) _" X/ D% e2 C* A$ z
- if($result){& m! Q; w- m+ v# {8 K
- if($result['error_code']=='0'){9 S: K$ ~) {$ S) G m# |& A( z N
- print_r($result);5 W0 \$ ~ `( r
- }else{6 e6 R) H" F" o5 K5 B
- echo $result['error_code'].":".$result['reason'];
0 h: T" R; \$ o" J9 @; g - }1 Y# ^' w' j. X s
- }else{
. v2 T" U" O' ~+ U$ C& b ` - echo "请求失败";
! O* u. K: N6 w9 N# y - }
0 q9 e, N* g# c* x# t7 T0 j - //**************************************************# h' |, A" N; d0 s6 N
- - |1 f% ?6 G3 {% e8 D
- 8 m g- E6 ^1 H1 p% U F) Y4 e
- , d+ A! P, L6 K$ ^
- ; I. S5 U8 B1 P$ H0 a1 D
- //************4.图像识别************
1 H. h! x4 ^( H7 U - $url = "http://japi.juhe.cn/image_recognition/check";/ D( B3 w) m# B7 h( W: Z: B
- $params = array(
2 S v, Y9 U: A" f" I' t9 K9 q% W( P - "file" => "",//上传的图片
( n+ b7 u: L b9 l) ~1 X/ L( I - "key" => $appkey,//APP Key# H# Y1 g2 J1 k( a- y6 @
- "pname" => "",//包名
& x6 X( Z- X! [9 e$ V h- C9 {* O - "device_name" => "",//设备名称(如android OS或iphone OS)
& @9 }" H3 B8 M; l* v% ~9 v - "device_version" => "",//设备版本(如:4.0.3)
8 V x' ?+ J- }; z) L# \2 ^" }+ U% B - "latitude" => "",//纬度* Y3 R; b: c6 y3 |( m$ @- i
- "longitude" => "",//经度& M# W r% m6 m/ Y
- "uuid" => "",//设备id
& J1 h( t& l1 I* D$ d& I& b - "zone" => "",//请求地区
8 C. f" a- J6 g' T8 v$ c3 N! e) m0 k - );
3 C' U$ u1 [ [5 U/ i M2 W - $paramstring = http_build_query($params);
2 z6 @) T& e0 W - $content = juhecurl($url,$paramstring,1);
5 D! f3 V; L5 [9 H9 f7 Y+ m7 y; | - $result = json_decode($content,true);1 G1 ]% y& t; Y! v' ]3 N
- if($result){
( }& ~! ~! m& r$ C. @1 L - if($result['error_code']=='0'){0 Q$ D, j& V; J
- print_r($result);/ p a- h8 k ?: c% m) \. ]
- }else{
3 h! B2 M) Z- o& R7 \6 }: F - echo $result['error_code'].":".$result['reason'];
! Z' X3 `! \ m$ G" P1 Y - }1 X$ x4 j- n; v
- }else{
$ J! P& V' f3 j0 P( Y5 ` - echo "请求失败";' c3 d" o! H1 I3 x( c9 U! c. s
- }
5 ^ V1 U0 ^4 H$ u9 x# k' J$ ^ - //**************************************************
7 O7 t; A" p1 j. G+ }7 ] - ! q9 P% H- B' V3 u) C2 l
- 7 o2 _, \5 g$ \2 H$ I4 C/ ?/ T
-
( I% S+ c, O# T - 6 A) D; }3 ^, a& Y( m. o, V0 f/ i
-
: |8 |1 t: I4 n) q+ C" H - /**3 D, t; c5 I9 s/ J+ q. h
- * 请求接口返回内容
' U. C1 g+ U e3 e, \% }8 h - * @param string $url [请求的URL地址]5 N4 [8 M+ e& y* l3 y( @& U
- * @param string $params [请求的参数]& Q/ v1 E+ r0 T, {) e; v
- * @param int $ipost [是否采用POST形式]
: K3 _% r+ {7 j* g" |; } - * @return string; D( k& K# ?. J! H5 Q3 H
- */
% t9 a5 s" {8 @- x+ G8 u6 `* Y - function juhecurl($url,$params=false,$ispost=0){4 k* R: T! P8 \
- $httpInfo = array();
4 a% d* Y! n `5 Q - $ch = curl_init();2 C( y- i$ G3 l6 o) H9 }- C2 [: U
- , |. s. K, R( F- j. R, s+ X A
- curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
5 E% J M2 i" @: N - curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );% i7 D. [1 K* o- {( b& |
- curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
: e5 Z. E: M. i7 G# K - curl_setopt( $ch, CURLOPT_TIMEOUT , 60);. j2 P) g$ `8 T9 d# S, i
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );9 B/ ]! h! o1 A
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
2 k8 D! n" d" }" z9 h - if( $ispost ) w$ b" f! ^9 h2 A
- { O& V0 d- f9 p: T2 ^; |8 i
- curl_setopt( $ch , CURLOPT_POST , true );
* q, |0 I2 x! q2 x3 [" L+ G) o - curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );; g3 U& T1 O1 I [4 c8 ~
- curl_setopt( $ch , CURLOPT_URL , $url );- n1 G- [8 D: _" i3 Y
- }
9 b6 [$ c, J5 e - else
; _' B0 p2 K2 D3 J+ G# j: W( j - {
) v* k3 v+ a. i - if($params){
6 _: S$ Y. o, O/ w! } - curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
* P& V e, D+ i+ w# F% E( s$ l - }else{
& `6 f& A+ ~7 C) @ - curl_setopt( $ch , CURLOPT_URL , $url);- k [3 K, g( L3 M# \# O
- }3 f- j9 | i1 c& d& M3 I
- }
8 D* b% q6 N: \( F) m - $response = curl_exec( $ch );# u8 F' `$ _9 F% I, L
- if ($response === FALSE) {6 s( I$ _1 |4 H
- //echo "cURL Error: " . curl_error($ch);
8 V4 x1 d8 k5 | - return false;8 [3 s9 E' K+ n" C3 `$ {/ K1 I9 z+ b
- }, M3 Y l o2 ?6 Z, W
- $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );0 t! C, Z1 D% v/ p
- $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) ); U' O# A R! Y+ V, W# b8 G6 o& A* Q
- curl_close( $ch );
. c' W/ t; @& e - return $response;4 u) d, m+ @5 T- d8 a1 q( H) C
- }
复制代码 : e, n$ ?; k: @6 o1 j
- Q7 Z, h, u c1 _ |
|