管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。
) C0 [1 Q, @+ G4 B e1.添加商品信息0 C. x' l1 g" z7 i+ r7 G1 W. d
2.添加图片
; ]/ Z- j8 X( n. ?6 M6 p3.查询所有产品; o9 G9 ~& s9 q0 ]0 i
4.查询某个具体产品信息
- T" ^: j, N# G7 T5.删除某个产品
3 L1 l6 G5 {* M4 S) i6.删除图片: i, z: [- t c; [2 ?) Z! l$ g7 F$ b
7.图像识别* j" [' J# X' L I2 L; c' p
& D* s! H8 Z( a6 e. K' q; e
图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey1 M6 h+ ?0 w; y2 V$ I" v n! r7 i# [
; ~2 B/ r/ G6 u6 h z" q
PHP示例:
* K) M; f% Q3 R: {9 G- <!--?php
, m% e* v, B* Z* ?; X) G+ g3 T- h - // +----------------------------------------------------------------------
( v2 E9 x# T$ m# z7 ?+ a( \ - // | JuhePHP [ NO ZUO NO DIE ]7 P( n6 d# p; r3 `
- // +----------------------------------------------------------------------
0 ?/ T. @6 ~" S - // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.
! N, G3 X( I- m! w; y5 D& i - // +----------------------------------------------------------------------
% l/ S% z: { D. [. i - // | Author: Juhedata <info@juhe.cn-->4 g9 D6 l' b" U! y" c1 I% l
- // +----------------------------------------------------------------------
% k: N; U; B7 A4 a8 t4 f9 \ - - c5 x& m o7 w
- //----------------------------------
+ e. G2 Q: C( Y+ A3 ` - // 图像识别调用示例代码 - 聚合数据8 h, G1 ?6 i! i+ |! L* e
- // 在线接口文档:http://www.juhe.cn/docs/117) v( k2 U% j, J) ~* q) B
- //----------------------------------
: l9 ?* ^* {' I1 \7 c; H8 R -
5 {4 N' G- T9 J6 e1 T: j3 ] - header('Content-type:text/html;charset=utf-8');! P. F' x7 F8 E/ @' C, s
-
. b- b) U9 r, C3 Z7 Y - 4 W* k! b& _ {: Z1 q" R
- //配置您申请的appkey) }. O" m; J3 E7 ^- m( O
- $appkey = "*********************";! s: j; X' x3 W8 ]1 }
-
1 d: \2 v) k4 P& |( t -
# y0 i& P0 Y ^0 X# ?3 q% p4 N -
( M8 G, ?5 L) v' g- e -
# e4 W7 W0 K9 u- U4 G8 M - //************1.图像上传************2 I; Q: B$ P5 L$ o
- $url = "http://japi.juhe.cn/image_recognition/upload";) p% a8 X ?& w
- $params = array(
/ Q5 r& B0 P X" [5 B' [ - "file" => "",//上传的单张图片
* y9 e& `0 W2 h8 E4 X - "key" => $appkey,//APP Key
# V8 z5 |& ]+ d5 i6 | - "pname" => "",//包名* e" x! ?5 q6 X5 I x$ J
- );0 q* K% W- E# c2 O- H% c1 C
- $paramstring = http_build_query($params);
, P+ i0 W" W0 g& K; S0 ~- Q' \ - $content = juhecurl($url,$paramstring,1); k. F8 R* C/ h# n8 E" K+ d
- $result = json_decode($content,true);2 S$ L! B+ a9 o
- if($result){
% m* R4 F$ ~" [ - if($result['error_code']=='0'){/ j- z- Q. N% S# \8 g: M2 Q- Y' _
- print_r($result);
& ~8 D' j$ G. r - }else{
* t% B+ c$ w% N; ? - echo $result['error_code'].":".$result['reason'];% c& s/ X3 L# o5 H$ d
- }
6 H! d8 v( m6 R7 Q& u5 k - }else{- _0 Y$ x$ q. Y1 d2 r0 B
- echo "请求失败";
% i7 K$ o0 l2 j L; r. E) M - }" w' { W1 u1 I3 b$ o$ h. J- _
- //**************************************************7 Z5 B: J- B# O0 n: Z! ~/ _
-
- c: e( }, I$ d! A$ g% g- F -
: d0 L& x5 T5 H' p$ p: ? - 7 Q+ u! C) G: w( l) @) O
-
3 n" y- U- h& o: D - //************2.查寻上传图像信息************4 ~8 \, d2 ^" Q0 a
- $url = "http://japi.juhe.cn/image_recognition/findAll";
) U- r" R9 O- C0 x& q( V+ x - $params = array(
* X3 `- o/ z% H& I/ q - "key" => $appkey,//APP Key
8 `2 i6 d R2 l* F7 e - );
4 H8 r, l2 x5 }- l N" L) [* ]8 q - $paramstring = http_build_query($params);
& e6 q( @3 ~2 y* B @ - $content = juhecurl($url,$paramstring);
5 e ]- {9 ?. X - $result = json_decode($content,true);& N" R& R8 _- ]4 [
- if($result){" |7 t7 p, T0 Y% _2 v0 \7 B
- if($result['error_code']=='0'){
3 Q4 `1 G2 R! C- T8 s - print_r($result);- h' [# F$ x' H/ p4 e
- }else{
. ?4 c" B6 p$ E7 n7 c - echo $result['error_code'].":".$result['reason'];
# b. J' M$ d) o) _, R. ` - }
' ] `; D! I8 n/ P A$ i0 [ - }else{
: ^- a7 k+ }* A& I3 g( ^) L - echo "请求失败";
, D( G2 V } ^5 Q - }
/ [5 j/ X {7 W) Q - //**************************************************& c p3 d [* m
- + x4 |' d/ _, T6 {6 h7 I G& r/ o
-
4 w2 s" m* \% ? s$ s0 t - 8 U1 e- Y, c6 r, a& S" G
- " c) O+ Y. G) e1 i) }( q7 [
- //************3.删除图像信息************
3 [) R3 ^3 S7 d5 E1 g" t: e - $url = "http://japi.juhe.cn/image_recognition/delete";
& ^7 p; I6 J7 v/ f3 X - $params = array(
- m7 Q1 o9 v* ^1 s7 i* V - "key" => $appkey,//APP Key" I5 S+ f% [! ?: y$ J9 ?
- "imageId" => "",//图片ID
* [% P& [0 i, X0 z) ] - );
D5 k; C B ?; f - $paramstring = http_build_query($params);
0 E" T' _/ J1 X" d; y: {5 h8 ? - $content = juhecurl($url,$paramstring);' u: d& }- l7 t% ?# h
- $result = json_decode($content,true);
7 Q3 P# O, f6 X" }4 r - if($result){7 \% G, n. r: d3 A- M0 x
- if($result['error_code']=='0'){
, V/ l8 e! a; O' _/ N( i - print_r($result);1 a, q/ F4 v+ L; |$ P8 `" T1 i
- }else{
- \8 x6 I( W/ p - echo $result['error_code'].":".$result['reason'];" a8 s7 S4 e& J+ y& G
- }
7 B: G7 z# g3 d( a# E2 Q - }else{
9 n1 \* H0 \) B( D - echo "请求失败";) B% R% u) G0 W7 v# y$ a
- }5 b8 \# q& L F3 Y
- //*************************************************** r! y' I9 p9 a! B) f: T5 @
-
) n: _7 y- w l3 X$ u -
' N# f3 q/ x, a$ B -
7 a+ s+ I8 O$ x - 4 S7 E+ |* b9 D4 X
- //************4.图像识别************
3 @3 i7 o4 ~3 A: }. Q - $url = "http://japi.juhe.cn/image_recognition/check";
9 ~$ N4 q( _9 v$ P4 y7 r - $params = array(
4 e: l# p7 j) z9 Q - "file" => "",//上传的图片
' Y# d8 \6 H3 F8 y; F7 X6 ~) Q - "key" => $appkey,//APP Key2 |- N) `. x3 I8 k" t' y# l
- "pname" => "",//包名
4 W8 o' a- F4 f# o - "device_name" => "",//设备名称(如android OS或iphone OS)% c! f: v) n+ l+ _, p$ K( z6 V+ a
- "device_version" => "",//设备版本(如:4.0.3)# m2 m. P4 D7 o& B' p0 J. S1 U
- "latitude" => "",//纬度 v5 Q8 {" P2 p2 v# b) R# }
- "longitude" => "",//经度
& F+ y' V2 @+ n6 r - "uuid" => "",//设备id
) f% B: R* U; _7 c$ T% C4 _ - "zone" => "",//请求地区
0 ]' B; p1 p0 u. p7 g - );
# D- B# r* Q( a7 O1 @2 S - $paramstring = http_build_query($params);: k [8 s: X' [' G
- $content = juhecurl($url,$paramstring,1);' p. t+ I; S9 l) b
- $result = json_decode($content,true);
# R& w& p& M- F - if($result){
, v @1 N* d) [* A - if($result['error_code']=='0'){
" M! y1 T. l. h - print_r($result);
. f8 p7 ]5 Q/ c+ w - }else{; y* h P: B0 ^% Z ?' ]( c+ s. O! |
- echo $result['error_code'].":".$result['reason'];/ Q' x/ w$ H% u9 t( @/ \
- }
) g! I8 h1 s7 B/ a- B1 e* _ - }else{! U( j. q a1 Z( i! D& E8 P6 d
- echo "请求失败";, M9 z" @8 D! m! L, n
- }+ O1 d% T4 @* e E; d& Z" C5 ?, w* E5 i
- //**************************************************( \2 k, `- T3 ^; G
- 5 S; N5 R5 G. y1 B- p
- ~; R- K( ~3 v/ {9 \( U `* L
-
1 J8 z7 o8 O* C1 t" E9 _4 ]6 N" Q - 1 j6 }6 Z* x! \2 X( q
- " [9 J P" G4 l. Z( Q5 }, {
- /**4 L- X' j- Y* w0 Y
- * 请求接口返回内容2 u8 c8 r# b$ F- _. d4 l
- * @param string $url [请求的URL地址]0 } n0 }# q" m0 u4 U4 r* I6 p
- * @param string $params [请求的参数]
( N8 b7 @8 z- ^/ Q f3 A8 b x - * @param int $ipost [是否采用POST形式]
( y6 v6 r: O% G9 j1 s8 q: P - * @return string
( j8 }, q- e9 g# m4 f4 }. [% G8 g3 ~ - */- n$ Z: k' T$ }7 Q! L
- function juhecurl($url,$params=false,$ispost=0){. {9 J6 l. R/ v: [, t
- $httpInfo = array();
, `/ I) w4 Y4 v0 g+ H$ U - $ch = curl_init();) s- ?& A6 t6 b) S# Q
- 7 _+ f r& {, ]
- curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );7 k" M+ R. U2 @* _* |! c( R$ A( y }
- curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );5 J$ ~; R; ~3 G' S
- curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
1 e! ?7 n1 O6 i5 D* ] - curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
' }6 M" c) Z7 j- o" Z. x! N - curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
$ Y7 W/ ]7 D* l; } - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
+ X9 ^4 ~+ }% r! Z. X - if( $ispost )
' O# ^. y9 @, _5 B: T - {: s& q6 F' N, g# O: E/ L$ X
- curl_setopt( $ch , CURLOPT_POST , true );5 V1 }3 H$ V A) E
- curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
! j! F# N3 \% h) |5 f. S* O8 s8 d/ B - curl_setopt( $ch , CURLOPT_URL , $url ); K6 I& s `5 D0 ]. s" H
- }
- e( H/ Q: |7 j- z P8 U - else
% a+ k* P9 Q: D$ `5 i - {8 t4 R, q$ P" v
- if($params){
r" n( ?: y) G2 I8 p* w - curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
+ z! D8 h% a& \0 ^ - }else{
4 I6 t( m1 l: { - curl_setopt( $ch , CURLOPT_URL , $url);. Y; w8 R& |- i' u3 \( `" R
- }
; c* w" X2 d" l s- u" O - }
& [3 G" g2 u% s - $response = curl_exec( $ch );$ E: H- Z2 X: E/ P0 l; H
- if ($response === FALSE) {
3 N8 W3 ]8 L: q$ s - //echo "cURL Error: " . curl_error($ch);
4 {& j5 S t! \, F7 J8 _ - return false;7 B, a1 s6 ^$ E& q, P4 m# e! r
- }
- ~* s- T/ M; V1 Z. _4 Z - $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );/ ]; P: U w' {9 o* C
- $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );+ F) c, h0 r) j+ d" ]
- curl_close( $ch );
; M/ g( {3 g6 T% s1 J5 u - return $response;
, ]8 k, P9 d8 X- C# X- j* W - }
复制代码 / y4 O8 s2 a q/ _ P6 n
2 y7 I- w5 A* f s; @ |
|