管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。
2 S$ `1 v6 M/ e* S! u/ [# `1.添加商品信息. J2 y+ }0 q- y2 \+ \ H
2.添加图片
$ j$ b- F& A# ~9 J# e8 ^3.查询所有产品
# {- B2 @( a# L2 I! Z0 Z4.查询某个具体产品信息
: m. k; r3 I1 [0 ]9 |3 y" L. ~5 K5.删除某个产品
' q6 U6 z$ A0 [/ i6.删除图片
, p* b. X L- w3 b( ~6 q" l7.图像识别" d# `; M! c2 B4 E# j
/ n/ X. `! D+ D图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey
p, a$ }6 }9 \8 ]4 c& ?( v# p: P' ]/ H! `
PHP示例:
8 j3 K; g2 ?% K- <!--?php
$ { e X( G2 z8 q w5 ^ - // +----------------------------------------------------------------------) g K9 Z' K# O; `0 y9 k. V. J3 W. |1 k
- // | JuhePHP [ NO ZUO NO DIE ]
* G% y% p4 E6 G% Y. m) {" x9 u0 W! z - // +----------------------------------------------------------------------
' X: T& ^) G. B. ~7 |' A1 f0 m - // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.
" N* N+ t8 {3 T/ w+ o - // +----------------------------------------------------------------------9 H' @/ F, c. V9 x I
- // | Author: Juhedata <info@juhe.cn-->
4 ]; b' r; g8 g, i' {8 T0 g- v2 m& n% G - // +----------------------------------------------------------------------
7 A7 s: W' q9 q( W; _ -
% f0 B5 j1 J* O' ` - //----------------------------------
: P# B) S' A- t- U - // 图像识别调用示例代码 - 聚合数据9 X( P5 X. b4 ?! g. [
- // 在线接口文档:http://www.juhe.cn/docs/117
' g9 b# ~" ?% K) @% Z; G - //----------------------------------
5 X s; [! j3 M! U0 i -
& ?: I; |' E6 C5 x4 m+ q2 H - header('Content-type:text/html;charset=utf-8');
) n- Y) T; h5 y$ y) O -
: g# t P; l5 p. t7 z - & ?9 ^7 ^" d( O0 P* |
- //配置您申请的appkey
3 ^2 x/ H$ X7 K n* \# ~; j - $appkey = "*********************";" a2 s) g4 M! `: h' t
-
1 t9 V! w. ~) N1 M4 u; `9 d -
( _( E& {1 Z# c/ s# ^ -
8 v6 w3 a' {" o# U) E - O& b8 d$ c' m
- //************1.图像上传************
9 Y6 G6 t6 I- n+ d - $url = "http://japi.juhe.cn/image_recognition/upload";
+ m( _& b" l. e. {) x* P - $params = array(' E F" l9 j5 @6 M. P& o% ^6 |
- "file" => "",//上传的单张图片. }2 v2 u' |6 c; `7 V( Q/ x2 S
- "key" => $appkey,//APP Key8 }/ w. E" x1 q0 a) k$ u# G
- "pname" => "",//包名
0 ^, w* B! I* S8 {* [+ _! T) n. i - );1 A, I4 C# c) b+ z* C# n
- $paramstring = http_build_query($params);
" f& |' u* Y7 g - $content = juhecurl($url,$paramstring,1);
$ q( J2 `7 \4 u- N# d+ M - $result = json_decode($content,true);
/ V$ |3 h6 R1 y: H0 N5 ^4 f - if($result){6 m7 K* I% u" G& [, M: J# ?" ?5 [& y
- if($result['error_code']=='0'){* z! M H/ s r/ A
- print_r($result);
: S! I+ k+ ^5 l3 n - }else{4 {* G& V3 W9 m/ T
- echo $result['error_code'].":".$result['reason'];: \2 X1 J4 }7 j2 C$ m! k
- }
+ m5 {3 f# ?! n F& ` - }else{! q0 o# N3 V9 i5 P+ g0 {- x
- echo "请求失败";
+ z: {7 B' ?, ]; f - }/ V0 j5 j1 @ F% N5 O1 D9 w6 H
- //**************************************************. Y. d. v, k3 ]
- 4 o6 Q7 V4 T) x0 b+ _* Q8 _
-
8 J, b k( c4 F -
, g) Z" S, N" d5 M/ D -
7 c) l# Q, P$ R, I, j - //************2.查寻上传图像信息************
/ |2 z! ^4 h" R( u: j8 Q7 f& c - $url = "http://japi.juhe.cn/image_recognition/findAll";2 f/ F( d! s) ~ y: ?
- $params = array(' Z- `! H7 e! K' b7 h. z( {1 }4 Z
- "key" => $appkey,//APP Key# {8 q4 P! u; b, X+ k& n0 S' l* D
- );0 i1 i1 Y7 t/ r: }" N j, |
- $paramstring = http_build_query($params);
* ~) o! O0 U; @) Q" O* [ - $content = juhecurl($url,$paramstring);$ d9 I6 k/ C y, B& x# ]
- $result = json_decode($content,true);( W4 H+ T/ W- U$ c/ n& k' t
- if($result){
" [! r* ?, h" ` - if($result['error_code']=='0'){
8 p- M G$ o# @4 J: E( h - print_r($result);
+ N J! `8 r. l8 W - }else{ x& n9 [& P( l2 l3 ~9 h, w
- echo $result['error_code'].":".$result['reason'];+ a% S) x/ Z# d' C/ f1 [
- }
9 u4 W( @* h4 t& ? - }else{1 y6 ?3 i. e9 E' y: c
- echo "请求失败";- Q/ g& ~" v& b% e/ L
- }
O( p7 B$ V+ u7 s+ L/ c* e6 q - //**************************************************
6 H; L+ W5 r7 @7 P d0 L - 1 K0 T9 N& d* `1 R0 o
- 4 a& ]& C) U3 `
-
; [; q* R6 v7 M, i" r5 a M6 ` - ' ~) x' W' n7 i% F2 L5 Q( c& o
- //************3.删除图像信息************
1 Z3 u% q/ L8 x# n- Z7 g8 V3 B - $url = "http://japi.juhe.cn/image_recognition/delete";# ~$ D c) F. U% f. E
- $params = array(0 |1 A3 P1 s0 Y; S! n( f9 L4 f
- "key" => $appkey,//APP Key
4 k0 k* H/ H1 h/ O# }! q - "imageId" => "",//图片ID. u& T" O$ `5 m7 w
- );
) v2 b( ?+ t, ?/ S4 w5 } - $paramstring = http_build_query($params);
2 @) |: V* x; R7 N9 J# `" N - $content = juhecurl($url,$paramstring);
5 H7 S) f/ e% d2 r - $result = json_decode($content,true);, p: _- z* W' E2 J R8 r& ~# Y: b. a' S$ ?7 O
- if($result){
; K0 S; ]8 K. U) ], E* ~! ^ - if($result['error_code']=='0'){. Q9 P Z& o6 r, b6 h* Y1 y1 t2 T+ w; k
- print_r($result);! K6 G6 X& J$ X$ ?2 S
- }else{
( B0 C" c% h5 E9 p( e w+ I - echo $result['error_code'].":".$result['reason'];) S0 F6 G" j! U
- }/ O0 z/ v) d, U% B) E' ~
- }else{2 R' d% k* X: N4 q, v4 k
- echo "请求失败";; w: [9 e0 k8 t$ a, h) `7 O
- }
' a/ E( W" J s3 P - //**************************************************
7 J Y2 a2 y( m$ V5 @ -
% z, O! W- d- |7 q+ o - 7 ]: d1 r% j0 a6 B% R
- ( u$ W" T3 [( `& A. k$ K6 K) S
- ; L) r. _& R# U% V6 e# i
- //************4.图像识别************
# j7 L$ Y" u5 {3 @! o( K - $url = "http://japi.juhe.cn/image_recognition/check";
7 U3 W/ z7 X7 J5 ^; r; V - $params = array(
5 p1 { ~' ~, f3 C. K4 @ - "file" => "",//上传的图片 r/ ~* J2 g) ~# ?' _2 I
- "key" => $appkey,//APP Key& y6 G7 C- x/ Z; e N
- "pname" => "",//包名( ?* v! I+ L( k) p6 A4 E5 i
- "device_name" => "",//设备名称(如android OS或iphone OS)7 a% Q$ B2 ]5 W( G8 N4 v8 L: M
- "device_version" => "",//设备版本(如:4.0.3)8 h8 [7 r* {% r) l, n$ L+ d
- "latitude" => "",//纬度! m, r1 J, b8 ^6 Q K
- "longitude" => "",//经度) k) t8 c5 z( }! z b9 {, b2 E
- "uuid" => "",//设备id+ G" @2 o( j3 s) x% F! D
- "zone" => "",//请求地区% }# j1 @: R. c7 \4 \/ O
- ); j% i5 |4 W3 I5 h% C3 g2 j1 C
- $paramstring = http_build_query($params);/ u' ~1 a* V! r1 O4 L
- $content = juhecurl($url,$paramstring,1);, @+ ^* N# a& G
- $result = json_decode($content,true);$ z# E5 q) u2 y
- if($result){
6 Q+ p- b9 Z% ]7 W' E - if($result['error_code']=='0'){
9 B. M e8 f/ v - print_r($result);
. e& F1 V, v) \2 O0 A( E - }else{6 o! Y3 A- s8 o4 h: O p" m% [
- echo $result['error_code'].":".$result['reason'];
# j0 R4 Y" b1 g1 c8 A - }# `9 Z+ W* o$ p5 c
- }else{* \2 l* u, I& O* K. M* ~% V- H
- echo "请求失败";! K' B3 d7 W2 V! x3 D
- }
0 T. d- z; Z8 M4 j - //**************************************************
4 H# t$ D2 S1 \8 @9 m$ D5 J# x - % p$ C; {3 ~1 J. E
- 5 D% k" a! Z" T. s0 [; q: g
- + D0 S8 r# z# g4 _, u
- 2 l @" ?! H' @- k- i
- ! t6 s" _: }( {9 C a9 A9 Z
- /**
, m% e% ?3 s. T( l& \6 r - * 请求接口返回内容
( }7 m8 A# S. v) @! J - * @param string $url [请求的URL地址]! b6 D6 s' {6 P0 w. Y
- * @param string $params [请求的参数]
+ T4 m/ L( B$ {. ^- S1 F- M - * @param int $ipost [是否采用POST形式]
$ [& h- X1 Y# H0 { - * @return string
( R; i3 }. O" P6 g" r! ]+ n, y$ H - */
" l1 v K+ z( [3 W6 k - function juhecurl($url,$params=false,$ispost=0){; F$ L/ b D: v) ^9 S. r& z0 u
- $httpInfo = array();7 {3 v2 c/ M% f( h2 @$ c6 C' W) S
- $ch = curl_init();
& D2 ^9 I/ q! n -
* g/ `& I0 }: d6 C) B1 b2 j, t! W1 k - curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
7 V/ d3 ^+ Y( B5 l! G5 M - curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );) v( \/ ?6 ?3 ~7 c( r+ \8 c
- curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
3 q( a+ G) Z, {- w - curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
% g4 |) r! J! o5 F - curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
( v. j/ ~" h. s- ^2 \2 O& f - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);, t& R$ E; ?4 ^7 q
- if( $ispost )
6 q. o! {( k; q* x% G) ] G) x5 k. O - {: d' v4 ^ v7 N( ~2 l
- curl_setopt( $ch , CURLOPT_POST , true );) X' s! y7 U# c b0 h. s
- curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );3 S3 |5 z1 C- y8 a% x3 |4 Z; d( k+ S4 n
- curl_setopt( $ch , CURLOPT_URL , $url );3 O" }- v) K @* M# \; s) j; E* L1 t3 O
- }9 }0 O3 \. M, L$ ?; l( }& p
- else. a5 E0 l- D$ ~0 e- H( M6 B) I
- {
$ U3 i- N& p9 }# |- s! g - if($params){
- H: m1 e1 \4 g9 K' I. E, Y% R- z - curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );, U0 }; g3 O, h9 Z0 ^. j
- }else{
; N$ ?" H5 B2 J6 e% ~0 P, u& {& j - curl_setopt( $ch , CURLOPT_URL , $url);, L) T+ N6 z6 v3 D4 B. |
- }
8 ]$ E/ M+ N; m3 ~' ~0 f4 D - }
" R/ R. v6 q; E$ y+ G" H - $response = curl_exec( $ch );
l) E5 j/ H5 o' g k1 n - if ($response === FALSE) {# F# o. s7 C- A% V" z
- //echo "cURL Error: " . curl_error($ch);
+ \3 C7 U6 G: d! ~1 e$ ] - return false;8 f3 u: ]6 s A
- }+ s$ ?5 s ?& N& L
- $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );7 m$ f1 i- y' T/ n/ B/ y
- $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
1 h1 \% l) M8 m7 [) S8 P4 Y - curl_close( $ch );
4 _5 ~: e$ ^" \* Q! {6 Z - return $response;% U7 o) X$ e: A. d
- }
复制代码 o5 g, c4 [5 R" Q6 A
4 M) m1 o3 G3 N/ ?5 V |
|