管理员
   
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。
; b$ r4 c: k* l; N; F, x1.添加商品信息& y! \' v0 B0 Y1 J7 Y+ ^( K
2.添加图片
. H. g0 p: z$ R! Y. \4 A3.查询所有产品" D5 P- o) O+ M8 B
4.查询某个具体产品信息4 ]1 Z: \& {% u. h$ f+ q, {3 z
5.删除某个产品8 }" z8 h" h6 [9 ^! V
6.删除图片
+ ?8 W# k0 ^5 K7.图像识别! y' P! j% O8 ^# H
9 D+ Z0 R3 Z" c3 k图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey) R( Q( c7 @% s% T8 h
' G5 |! L+ H- p/ N6 L, |
PHP示例:( u$ [: o! A$ C5 y$ B
- <!--?php/ W( H( \0 L( u
- // +----------------------------------------------------------------------
" E$ f: {: }$ k% d - // | JuhePHP [ NO ZUO NO DIE ]
) k4 d9 A' B2 D- ]# q- `7 }3 N - // +----------------------------------------------------------------------& A, x8 p( b% }4 O8 N& |# j
- // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.+ {4 j# h# O( g, v* y5 w
- // +----------------------------------------------------------------------
: b7 D4 I2 l- b G - // | Author: Juhedata <info@juhe.cn-->
; p3 N# ~& F( Q4 F: l - // +----------------------------------------------------------------------- p1 R$ e' e, _8 m8 L
- 9 Z8 y" V- y8 \ f+ P
- //----------------------------------
! ]" g1 P# S( z' E( O6 i5 P - // 图像识别调用示例代码 - 聚合数据
2 R9 f. u. C4 V W' _4 C: @! e - // 在线接口文档:http://www.juhe.cn/docs/117
$ z% o$ l, }+ O - //----------------------------------5 U% j( V) V8 k) [0 l5 {& Q& c
- 1 g* q6 E" f* [7 X) u
- header('Content-type:text/html;charset=utf-8');3 x7 `. }' h& A _$ a
-
! t! p0 v3 t1 w$ c/ C% a/ J) n -
9 J0 k, ?/ B" x. u* ~1 c' Y/ p - //配置您申请的appkey
+ ? K! v) r( W+ n: k5 Q) i - $appkey = "*********************";
0 U4 P9 ]& G- d* s - , ?7 r: t g0 M9 j
-
. c p6 {, z% ]! G4 f! t: W/ f -
& f+ [) x7 i5 h! g q -
% I3 H) {1 T& U3 N - //************1.图像上传************3 A% p W/ r4 P" y2 e1 x
- $url = "http://japi.juhe.cn/image_recognition/upload";7 r! t, D4 z7 Q2 c
- $params = array(
' ]! A+ P1 B' N* H6 j, E0 i - "file" => "",//上传的单张图片
) {/ V5 U6 S1 u4 S% ^( R' f - "key" => $appkey,//APP Key
' C; Y3 g8 ?$ o7 h A1 k - "pname" => "",//包名( i+ S) O4 Y# [, `2 E
- );
( l& D( i1 i8 p - $paramstring = http_build_query($params);& M3 `* M7 v/ e% S, q! a! u
- $content = juhecurl($url,$paramstring,1);$ j5 _; Y+ o9 C" I
- $result = json_decode($content,true);
! h. m" |6 X9 d7 z+ L" e O* u4 s - if($result){0 k7 H. |7 j6 v1 U/ t! a! a
- if($result['error_code']=='0'){7 T3 H x8 z7 W3 L8 _9 f! |. f; [
- print_r($result);0 U2 I# X* d/ A
- }else{ v# h1 X8 P& q& @, Q
- echo $result['error_code'].":".$result['reason'];1 d# `1 a! M- f6 z
- }
7 M$ }5 l5 ]* {+ l3 E. W% ~ - }else{' _; D0 z7 x$ n" L1 t
- echo "请求失败";
" f( R! n% G9 R( U/ O' P# u - } c, \9 J8 W0 @0 r- S0 P* U" D
- //**************************************************
4 O: c9 x7 B- _) Y% J3 L - : L- _" v1 v0 g
- 8 A' O R* \7 o; f I
-
. C A- x2 z% z% a6 [. n* K -
4 C! `1 b, H: D# b0 S1 W - //************2.查寻上传图像信息************
+ j; }$ P: E$ e7 e, u* j - $url = "http://japi.juhe.cn/image_recognition/findAll";' a1 S8 @! ~2 s
- $params = array(
& B a3 a. Y# C* u - "key" => $appkey,//APP Key1 }8 E5 s, p, {& z
- );
! t! k) f! a' Z- x - $paramstring = http_build_query($params);, u. A* A/ G* v5 d3 x; F, [
- $content = juhecurl($url,$paramstring);
7 Y/ o* L8 `7 G% \' y2 U+ P+ w - $result = json_decode($content,true);2 u& u5 \ B+ Q$ Z
- if($result){
# S# Z3 Z0 }- r4 c: z - if($result['error_code']=='0'){
! f& x0 s. x1 k) ?# [) R( [ - print_r($result);
& a% h( K a) G7 f+ i$ ~" F - }else{! d( X, H/ v( N( p( ~2 p
- echo $result['error_code'].":".$result['reason'];$ O# B2 k% F3 k
- }
2 B, W. o' `0 A& F- `( d - }else{
& f: V) C% Z* c - echo "请求失败";
# {3 o! f3 r+ M4 g* ]% d - }+ J: h5 [3 _9 G- i
- //**************************************************
3 z% A" k/ z6 H# m- m+ [ A' o. Q - ; x9 x6 O3 }& K; x Y: d
-
6 O. i% ]5 s- _+ j+ Y. {; r; S% p4 b( a - 0 r, `. M6 L2 M+ [; n
-
2 j, [4 X1 G- Z4 L! u0 d) j - //************3.删除图像信息************
/ s; y3 H1 `: R - $url = "http://japi.juhe.cn/image_recognition/delete";9 s# B$ x D w0 p9 A- x2 B
- $params = array(6 e. H. M# j2 ]$ i
- "key" => $appkey,//APP Key R; j" H. l3 b! X5 M2 x
- "imageId" => "",//图片ID5 U0 O4 ~# q" ?3 h( h& v0 C; A9 u
- );
! C; o* g+ Z) W% G - $paramstring = http_build_query($params);; d6 J f1 |. e# a' J
- $content = juhecurl($url,$paramstring);1 c3 ]% j3 `$ x7 K1 [) w
- $result = json_decode($content,true);
% ~7 e7 d- [, ?- i2 r: u) n - if($result){
^+ y; u1 n- ` w - if($result['error_code']=='0'){
% k' W0 s( r5 J& C/ x - print_r($result);
\! e1 j2 ^ o% l* b! z1 J! a2 A - }else{% I% ?3 e; x, h& s# A7 ^. Y7 O8 p
- echo $result['error_code'].":".$result['reason'];* b' v8 E+ O9 _0 C, S( v
- }
- y6 h: m( |/ O- \1 [# i - }else{1 z, H( G: x! d; d/ E, j
- echo "请求失败";0 m* |0 f1 S3 t$ ^6 f" ]: N
- } ^% H0 n( D( k/ g
- //**************************************************" w8 r+ S! N* q5 X, y- ~
-
! M: z8 ~8 g A& m7 Q6 C D" ^/ } -
. W% C5 B0 g6 e; K- L - 1 W. J6 O2 P3 X+ F- X7 |* V2 R
-
9 n' v( s P7 K7 R - //************4.图像识别************" t3 A9 ^1 d, e4 }; C' L, p% ]' ^: |
- $url = "http://japi.juhe.cn/image_recognition/check";0 @9 W6 y3 D' B, {3 u; V
- $params = array(# C" }) j1 |7 Y; J8 A
- "file" => "",//上传的图片
% M" @- P4 g0 b( d) f- k2 F - "key" => $appkey,//APP Key
+ A$ o. T+ h7 b3 Z# v) u( ~6 t - "pname" => "",//包名
" L0 y, s. X0 L8 G' G$ m# V& o - "device_name" => "",//设备名称(如android OS或iphone OS) ^: T: M2 D" \8 ^
- "device_version" => "",//设备版本(如:4.0.3)+ ~" w# e7 W7 B d& U! P, _6 {* P
- "latitude" => "",//纬度
7 d; q" \( C/ | s. A' a$ } - "longitude" => "",//经度' K9 n& t4 P+ D1 [: e2 O
- "uuid" => "",//设备id
' U0 M3 x# o- X. H( p* B" s8 w1 x8 ^ v$ X - "zone" => "",//请求地区
, m+ ?7 X+ N; o+ b' H6 Y - );+ s; |% J4 ^2 u7 U7 q
- $paramstring = http_build_query($params);
$ T; w* z9 {7 o, V+ ? - $content = juhecurl($url,$paramstring,1);
0 {+ K0 M* d, k) g2 I - $result = json_decode($content,true);
8 e# J& x' _2 u7 E+ }8 z% r - if($result){' ?" I7 w5 B' t2 @
- if($result['error_code']=='0'){
5 \& G+ n) N, k" ]; R; ` - print_r($result);! L1 N. z8 {- o1 T5 h
- }else{# r7 `/ J3 @2 C& M7 w- g
- echo $result['error_code'].":".$result['reason'];* `1 `7 H: m: K7 ]% j" m$ |4 [4 X
- }
7 ~* H K1 H$ w4 X - }else{
- ]# J1 V2 }6 ~! f# A& k - echo "请求失败";/ W5 h/ c4 y$ K* B" v; t
- }3 y2 }0 k9 w. H/ |+ Q! o
- //**************************************************
) l' T7 z3 W- ]0 L+ m -
4 ?/ Q; \. z5 \: D: I4 e2 O - * ~, U; |5 C' l1 f% d
-
8 @$ r8 I& X; U7 I. m. Q* K - 5 `; {) ?$ n! k5 O+ t% Z% A
-
: s2 z! @, `7 n$ N! m4 Y - /**' }; X$ Y3 R, x0 b+ `( {
- * 请求接口返回内容1 \% u& _! H, K* {! y8 Y8 g
- * @param string $url [请求的URL地址]+ u$ X: q }8 c& L1 @" Z6 a
- * @param string $params [请求的参数]& e7 D! _6 i8 D/ x Q2 q
- * @param int $ipost [是否采用POST形式]* c: ?; l; g; u2 p7 z7 [' ~+ {
- * @return string+ J5 V" q9 l+ y8 B
- */
! i( s' U3 Y8 u5 ^( U; h1 m1 K: x2 |' S - function juhecurl($url,$params=false,$ispost=0){& d6 C/ f1 J% H, C6 L+ ]3 Q7 R
- $httpInfo = array();
: u, a' m6 i: q8 j0 O# J - $ch = curl_init();
0 }: I0 p. u! B+ g - 6 V% e6 i' O# ~: G
- curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
' _8 [, G* Y+ V* B- k - curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );6 C, b+ A2 P, V) N: t' u5 |& h
- curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
' R% }3 O3 B& _; g - curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
( _" Q4 e- U* ?1 a& q) Q5 v& h - curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );8 e; w4 d& B8 {; H
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);/ s0 S A' k/ R- D. G0 ?. B
- if( $ispost )0 h+ Y: w, ?; M% S' t* @
- {: }. [ ?) [1 j& b" k7 S+ e V8 M. \2 T3 {
- curl_setopt( $ch , CURLOPT_POST , true );! p) B: e3 M' [$ s- m0 j
- curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
1 k" [1 m( O) s2 W* l - curl_setopt( $ch , CURLOPT_URL , $url );
, u/ k# g8 C' ~ - }
6 @' W! P9 `5 h - else
o# H$ X% R% |5 l4 V/ _+ n7 I - {% T$ {' n, X; v7 W1 q( B
- if($params){% n) ?: V. F) ?9 N" E( X+ U
- curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );2 a# A2 j3 J/ Z0 h" p
- }else{ n7 y v$ {6 G! H9 \: P+ H
- curl_setopt( $ch , CURLOPT_URL , $url);* F+ }* c+ J% M, Y, i& D4 v
- }& r0 _0 K4 R) G) H* v9 V \ Z( p t
- }, l0 c5 `3 d5 u
- $response = curl_exec( $ch );
2 [ v) _9 e; p' y - if ($response === FALSE) {' ?& ?& z* Z5 o K$ y6 @0 y/ W
- //echo "cURL Error: " . curl_error($ch);
" z* p3 h6 k5 ?1 ] - return false;
6 T) g" S5 @8 t: i) q - }
1 V9 G0 j) C6 k$ K5 q: ^ - $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );( X+ _/ E/ H; ]
- $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
$ r: T0 K" x5 ]% r8 R - curl_close( $ch );% M& E) L* U- x# |
- return $response;( z0 z+ n U6 X0 g
- }
复制代码 8 l0 q( o& \+ m D! @' v
5 }+ K" C: s: L |
|