管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。7 _ O3 L" t- W* W
1.添加商品信息
( H j& p+ V, y" \2.添加图片8 V4 r( ~* p/ s3 a9 A9 x) v0 X
3.查询所有产品
5 r0 P& ]* C4 g) J4.查询某个具体产品信息
5 }! g$ U& ~7 H9 E) K* }5.删除某个产品6 C# L0 w8 }/ d* o
6.删除图片
' b0 Y4 m( ^, _) l! C) Q: k ]7.图像识别* v/ J7 u' K; Y
0 `! y2 P6 k7 U3 V2 U
图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey3 C+ ~" t1 k+ Y1 S
( L) e$ x5 s H% ?8 N3 dPHP示例:
+ M: j. y+ C+ B, n, d- <!--?php& w6 t) i$ {; y; j. Q0 m
- // +----------------------------------------------------------------------
) ?% g, y) A# R V9 d - // | JuhePHP [ NO ZUO NO DIE ]; B/ Z' [9 E& v+ @/ u- d; A8 t% L
- // +----------------------------------------------------------------------
5 E c, h& P, ~$ ?4 I- d6 k - // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.4 C; j0 f- }3 Q' Z
- // +----------------------------------------------------------------------8 x& E$ k% H; A2 n$ Q8 L6 A
- // | Author: Juhedata <info@juhe.cn-->
' C8 w4 U# p4 a& J( v - // +----------------------------------------------------------------------
) L: u, G9 [6 i3 K0 n2 r5 K -
' Y) D% ~& U& H - //----------------------------------1 V" L/ V2 d' ~! _5 w: E
- // 图像识别调用示例代码 - 聚合数据+ o# l4 t+ }4 d0 t
- // 在线接口文档:http://www.juhe.cn/docs/117
! f7 i j9 P/ x% x7 H - //----------------------------------
. q+ u0 H' @1 v6 @! x3 G - 2 @7 o. z5 c5 A. P2 W' p
- header('Content-type:text/html;charset=utf-8');
" d( }: ]" E/ n I0 h, K& j& s+ I -
( _% u4 e" z8 t0 t& g1 b -
6 H7 d: r9 T0 P- `+ M% D - //配置您申请的appkey: z1 s" z& b; X
- $appkey = "*********************";
8 T0 K% V) Q3 A4 \: m -
6 s5 n0 {7 K3 m- t, Y7 a - , m5 ^- i G' M/ }! q7 X
- ; [2 s' ~* {) L
- : V& R9 b3 r/ C; `( @* A
- //************1.图像上传************
, I7 ]: N& b8 P5 m6 g8 n" e - $url = "http://japi.juhe.cn/image_recognition/upload";
2 K3 @( n0 v. l K2 O - $params = array(
8 Q& W. X3 @& |3 ~ - "file" => "",//上传的单张图片" D/ h* m3 p8 g6 y. A" m
- "key" => $appkey,//APP Key' f( \$ K% H. R6 w# ~- T
- "pname" => "",//包名 `% Q( T7 ?& w9 U8 Q
- );
( X: ?$ L: f m( i - $paramstring = http_build_query($params);
|! f7 @- E( ?: T( @ - $content = juhecurl($url,$paramstring,1);
9 U8 E- t- X0 ]0 S: G8 p% M& K - $result = json_decode($content,true);+ d; B0 b* v7 a
- if($result){7 q0 W. d4 Q- ]# R
- if($result['error_code']=='0'){
( p1 B, S$ g- P$ f$ k - print_r($result);) I! x I0 S1 a& w$ P5 M
- }else{
/ R* w7 F% k( T; k0 k - echo $result['error_code'].":".$result['reason'];
, a0 | `( x( t- ~5 R - }8 X4 p6 y( Q/ s. g# n/ M' m( P. T& M
- }else{* I$ C% {% L. k5 o
- echo "请求失败";6 n2 i2 V; G5 m/ L6 p0 N O4 @$ `5 s
- }) z; ^, `: B, F' h+ b' I6 q
- //**************************************************6 v1 H, C& a% c8 ]9 G
- 8 ^; z, p) g2 x G
- / x! S: G4 I {. ^6 h/ }6 O) W
-
+ O4 K& B* ~ I7 I" x - ( X* m1 Q; b7 t" e" Q# y0 q
- //************2.查寻上传图像信息************. ~5 v1 \7 \9 A
- $url = "http://japi.juhe.cn/image_recognition/findAll";
- K* d8 H9 Q; e; w - $params = array(
7 F, \) I" d& P' B - "key" => $appkey,//APP Key* b I; I" G$ y9 m$ n8 l9 U4 g8 Q
- );
3 u% N6 d. n8 M$ d' Z( R: h9 O - $paramstring = http_build_query($params);
U7 K) D [! T& P& k8 [9 c D* \ - $content = juhecurl($url,$paramstring);
2 a5 U2 T- l3 ~$ f' ] - $result = json_decode($content,true); J1 z# \ q7 R) V/ }6 h
- if($result){
1 D0 }, B# v4 s' l0 ], r, w9 _% n0 t% N - if($result['error_code']=='0'){) u3 r% z0 l8 z e& {5 v
- print_r($result);! a R3 e! _6 q4 U* [$ T
- }else{
( ]0 {1 |9 [, E3 t! R9 Y% V0 a0 v - echo $result['error_code'].":".$result['reason'];, ]: l: L9 x' O8 ?
- }
, Y6 M3 u" O3 ~" p, S4 M - }else{+ |, Y6 X9 o: h+ y: ~ i
- echo "请求失败";
% g/ z6 o! t' c9 ` - }
. M9 e8 W6 O5 P- s N - //**************************************************% b6 d/ t3 m5 ?$ L- Z: n$ K3 P" S
- / ]$ G( ^0 n/ j- g: _
-
3 D+ h$ D; X4 d" }% K4 h2 Q - ( `) n- o' D$ S' T
- 2 G9 X2 M! u1 Z2 j. m- |. W
- //************3.删除图像信息************
& @' _$ B( ?. v: b! P) P - $url = "http://japi.juhe.cn/image_recognition/delete";
$ d, w* B9 J' s' a0 ` - $params = array(4 L9 v8 C7 S E, c& O6 [
- "key" => $appkey,//APP Key! x2 x8 J0 h! D5 n
- "imageId" => "",//图片ID+ O/ r3 O \& s, m* @+ J/ E
- );/ z* l. m8 \, S4 R9 Q1 x
- $paramstring = http_build_query($params);3 i/ |3 d6 Y( \: x$ R
- $content = juhecurl($url,$paramstring);# U9 y. O2 K% ?- r \; H7 C; ?
- $result = json_decode($content,true);
7 d7 b; W( x- a - if($result){
% X$ i' S& F3 K" y. d. S" g5 U - if($result['error_code']=='0'){
: n! C3 P, K0 g X j' s1 p. k' @ - print_r($result);
3 k: k2 K8 H( q' M3 h - }else{, n# }0 Y& B1 @. G
- echo $result['error_code'].":".$result['reason'];# A+ O( C# t `) W
- }3 r5 c3 s" j+ E& c
- }else{( e8 {% L( e, U! F
- echo "请求失败";" }2 j' G3 ]5 I5 [7 X6 J+ P% C
- }
7 C( _8 B( G) f - //**************************************************% a8 I& S: P: p0 C8 w
-
* y- r) O" `8 L' C" N -
& r' D. C' L+ \4 p* k - 3 s# ~/ l* Z7 Z5 i9 ?
-
$ C4 }; j$ X+ o8 T - //************4.图像识别************ i9 @4 D* G* T# G7 p1 ~ R
- $url = "http://japi.juhe.cn/image_recognition/check";7 v# D6 Y0 S) b7 m S3 y$ Y
- $params = array(- g/ ]2 n7 v0 e, A( X. Q* U3 B
- "file" => "",//上传的图片
+ X1 T0 a4 I; y9 ] z( q9 ? - "key" => $appkey,//APP Key
S/ }1 k$ i- u, T# c# N4 v! u - "pname" => "",//包名
7 O8 L( Z% z. b( |$ v - "device_name" => "",//设备名称(如android OS或iphone OS)
0 Q9 T- h6 M6 f+ H" Z' { - "device_version" => "",//设备版本(如:4.0.3). Y6 V- y# j" M: o1 e2 a8 p. N5 s
- "latitude" => "",//纬度
; `2 {) X5 H4 ^* X - "longitude" => "",//经度0 ~- |% G" F. x" { Y* H, a
- "uuid" => "",//设备id7 S" ?. r$ r3 g# t% V
- "zone" => "",//请求地区+ d; M- r$ U1 U+ r; B3 y5 Y
- );
8 J- S( L4 j' c7 V - $paramstring = http_build_query($params);6 c; G& q9 v, ]# A& [
- $content = juhecurl($url,$paramstring,1);4 x, t% M( q4 ]
- $result = json_decode($content,true);. }. I- J' M4 W
- if($result){5 G% u' ~* d- Z* I* ?8 n# H
- if($result['error_code']=='0'){- `! @/ V% }; [) ?$ @& O# C
- print_r($result);1 F- A( e' }; ]* A
- }else{. T* M0 v- \1 f: J
- echo $result['error_code'].":".$result['reason'];$ _3 z! e3 ^9 U) e, l- f+ D
- }4 O; V# n' n$ d$ S
- }else{
; B- e: T- _! e I4 ` - echo "请求失败";+ t3 R9 h- I! S2 n ?
- }# p" S2 P4 f$ v7 T5 y
- //**************************************************
1 G+ g+ b0 v% ^; {5 ` -
" ]' m- B b& u4 M2 C -
- K1 ^7 I! }" `# X+ ]( b% [- R( b) } - ; G& v3 R2 D2 n: u! s5 N
-
5 d4 P! g% S+ B, S -
" E; z# |0 a) ^3 A1 e. x - /**% A8 b' \4 O9 y( M
- * 请求接口返回内容7 O1 ~3 a4 \8 \6 S7 f* K3 u2 L x
- * @param string $url [请求的URL地址]9 ~3 V) D3 |. e
- * @param string $params [请求的参数]/ Z( n- C( c, B4 T) n( a W
- * @param int $ipost [是否采用POST形式]
8 O' g( d5 a9 Z: z2 b5 s) R - * @return string
" D/ { b; v7 y+ W7 z' Y! { - */8 a) L- ~! }0 g4 G, y
- function juhecurl($url,$params=false,$ispost=0){
1 j8 f: K! k# X1 L - $httpInfo = array();
, N% a% Q$ F. `5 M- q - $ch = curl_init();
' Y. R: r; S, q, D+ \; q: ^# J -
! z9 E8 ]# t) w9 x! q. @ - curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
; L5 ]$ @3 t! [" q# j7 ~ - curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );
, N( V; A5 b8 @/ A$ p7 U - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
$ a8 k* b2 t, Y; \# M6 [ - curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
' Q8 V- v% H' F+ u: ?: e+ d7 V - curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
& w$ G6 z6 {5 M$ Y - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);% p$ O9 z% \( Z3 i6 e5 |! X
- if( $ispost )0 a! d, Q+ X6 ?, Y/ ? W' G9 Z
- {
) D3 l% H) q. S( y! X; e% f - curl_setopt( $ch , CURLOPT_POST , true );
- A! V3 p& }7 ~" g z! _8 m+ v - curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );( x( Q5 h u, ]$ [
- curl_setopt( $ch , CURLOPT_URL , $url );/ l/ w T2 L# | V$ l
- }
, |0 s3 U7 T$ g" [: p - else6 a7 R2 v; b( h; ^ l$ U
- {
" b" B/ N" Y. S8 J" d3 _" e - if($params){
( ]5 b/ |3 Z7 N' }4 A - curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
2 e& @7 R8 l0 o# K8 M+ j - }else{
( B% M/ X f* c& e - curl_setopt( $ch , CURLOPT_URL , $url);5 ~% c: s5 m+ N* j* D" G
- } H9 y1 R2 W8 [" p- E _) P1 u
- }/ \ H+ G |) F6 ~- K/ ~$ d
- $response = curl_exec( $ch );
* C! d, ~9 m% p# D. @$ z - if ($response === FALSE) {
2 Y" |& k0 ]0 E+ a I - //echo "cURL Error: " . curl_error($ch);) `; \' g* Z7 ~( g& N7 G H5 ~
- return false;
* e0 E, J: a& m* g) U' n, d2 N - }
7 b; N4 w/ o T - $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
, J2 C c4 W& W# M6 { ] - $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
; E( i: {. F9 |1 `. O - curl_close( $ch );
! ~# U& l/ H4 m: e# g! \ - return $response;7 G n" b& w1 x2 g/ s7 ]
- }
复制代码 0 W: R8 z& g, p. ^$ @- w- c7 O
1 }& v1 k* V5 ?/ W9 ^
|
|