管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。
$ c, }' N2 v6 R* A1 F# J1.添加商品信息5 ]* g2 r+ }* j5 I* W
2.添加图片
; x7 s" q0 j3 a! c8 V" ]3.查询所有产品# W) {, B+ R4 T' E" ^
4.查询某个具体产品信息4 y f+ \7 |! h4 ^8 d
5.删除某个产品
$ W2 p `4 w! n: f6.删除图片0 d3 d, p' q- C8 E+ x
7.图像识别
% t% O1 i& `% v9 M9 r. j( H
& |7 w o, \; ?( M$ @4 w* C图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey8 C6 F/ p, x& C2 r" i" C
# `/ B. d( X% \1 |+ P' ~PHP示例:
7 F$ j4 [& I5 w- <!--?php
# f' K* H* M9 {% u# E - // +----------------------------------------------------------------------) t, O; r, H: V" L/ n
- // | JuhePHP [ NO ZUO NO DIE ]( x" _6 ]3 }; M0 e1 @
- // +----------------------------------------------------------------------
Y& d* U3 P w! c; y) V - // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.
" x3 g w' }" X - // +----------------------------------------------------------------------
# K4 d* L/ v' [6 ]5 R! x& v) g - // | Author: Juhedata <info@juhe.cn-->; a% k$ ?( b1 H
- // +----------------------------------------------------------------------! h4 G# e3 r* h; d9 L
- ; w/ P2 N Y) V% F) q& J; q, k7 N
- //----------------------------------
1 ]$ |& i x, [; B5 o - // 图像识别调用示例代码 - 聚合数据+ K! d/ L' x# g6 q7 e5 x Z& [5 c( I- q
- // 在线接口文档:http://www.juhe.cn/docs/117& J! j1 v N& j( c2 Z: v6 R6 s
- //----------------------------------$ {* q q4 [* u% B% N( c% [! U+ r; r
- # c, U7 H0 E% m1 b
- header('Content-type:text/html;charset=utf-8');& ~, K9 Y4 ?0 x. f1 f
-
: n$ \# b8 M$ U) g - 2 B- _& m+ c7 W$ A
- //配置您申请的appkey' f* h+ Z. ^) F. D; l
- $appkey = "*********************";
8 I( I1 b' e' k% w6 D& q( D; M, H - , c$ O. |( v/ U0 a7 K. W, {4 \
- - I8 p0 ?3 s2 p1 t! D
- " \/ R. I5 Y0 ?( U& g/ [' J
-
2 S) i; ]% ]. L7 I* p - //************1.图像上传************
! }" d: ?$ `8 C L" m - $url = "http://japi.juhe.cn/image_recognition/upload";% X) |, x8 P3 F( A
- $params = array(
) v0 Y6 Z) R+ F( S - "file" => "",//上传的单张图片
* h) I( A) S# j/ o - "key" => $appkey,//APP Key
+ T- k+ b5 Q8 n - "pname" => "",//包名, P6 |6 p1 L" h3 J( v: r% c( D
- );: V' L4 L2 X4 d* C' Q& u
- $paramstring = http_build_query($params);) o3 `) N( [+ Z0 b
- $content = juhecurl($url,$paramstring,1);3 [5 |, w5 \% f2 K
- $result = json_decode($content,true);
5 F4 \( U, y1 j2 I7 c - if($result){
# M2 W H9 I" q* @ - if($result['error_code']=='0'){8 f( T' C" }7 l( S, L% I* v" e' J
- print_r($result);
1 |, `+ h- z# E/ s6 _ - }else{
7 _% U+ A4 U) M! R4 Y+ J4 F( ~ - echo $result['error_code'].":".$result['reason'];
2 e9 x; E) ` s1 {$ m0 Z3 u( l" @ - }% z% c7 m- V, k# z# I
- }else{
6 f$ ?; F, X% q - echo "请求失败";
0 |; q5 l: e/ ~) C7 ? w - }
1 O' F; J; O R. m+ V& [, S5 T - //**************************************************
7 d0 ]8 h/ g! ?- E -
6 w6 g, L# V$ p4 ^6 j; j* Y- Z -
2 P8 D$ X, O5 ]9 M% u -
4 _6 h/ Y. W; Q( X+ O - " o9 n0 b1 v# n U8 M" U# m
- //************2.查寻上传图像信息************: p* ]8 t: u) F! q
- $url = "http://japi.juhe.cn/image_recognition/findAll";
! T; B e$ U. `% a8 w* ` - $params = array(, Q9 m' n8 S8 J& c2 d& @
- "key" => $appkey,//APP Key
3 m/ D/ `/ \; }* w! k4 | - );
3 { [$ j) u, p4 `7 S( S - $paramstring = http_build_query($params);. t0 R, X) @$ X4 p: U
- $content = juhecurl($url,$paramstring);
$ w+ M4 n! i, {7 X - $result = json_decode($content,true);
0 e9 o2 V2 H% ^( Y5 ^ o+ G - if($result){
' A& Q4 O; p2 R+ k# r- U% @ - if($result['error_code']=='0'){% j' T* H& W, w5 U
- print_r($result);# x- F3 `( {9 d8 t. e, [
- }else{
0 f6 o% L4 U" {) E7 K O( j m ?0 p - echo $result['error_code'].":".$result['reason'];+ N+ ]* e% f8 m7 o% f
- }
- H. v2 a, D6 B0 C' m( ^1 b$ a$ r$ s - }else{4 W% X* w% p! A' w( ^
- echo "请求失败";
, ]8 H" q: G+ d7 x - }1 Q3 k5 \4 T- q) D
- //**************************************************3 E" h( l) E5 k- O& L$ F0 S3 ~
-
( A% d6 b* y8 h2 K6 I; _ - & \$ Y% f9 K* ?) v1 D
-
0 M8 K& ]7 A+ ]5 A% T - - ^) Y+ a* S5 l: |
- //************3.删除图像信息************7 s" Q6 M- v( J8 m9 [& L
- $url = "http://japi.juhe.cn/image_recognition/delete";. M( M' w. O; z; m) `3 f& z
- $params = array(
, o# I6 b8 d& f - "key" => $appkey,//APP Key
: S1 x9 s' m; x# `# A% \: } - "imageId" => "",//图片ID
+ g. A! }1 D( G, Q! O* {4 y - );8 Q% @/ K% Y! j9 N1 ^) M( O1 X3 l( J
- $paramstring = http_build_query($params);
& H( x+ r x% `4 J1 J- M+ d - $content = juhecurl($url,$paramstring);
2 A: m" O- Z' ?6 T5 y7 \$ Z; X, v - $result = json_decode($content,true);/ j( k2 h( w4 r! @. k% v7 z
- if($result){, J; ^. I9 F4 p8 B7 L1 s( V
- if($result['error_code']=='0'){! }6 d: N! ~6 l* x2 H
- print_r($result);4 C: A- G4 _: W: G. [
- }else{$ R! v. ]* o8 I! y% ~' u8 L; B9 @
- echo $result['error_code'].":".$result['reason'];
" I4 D) V* O) G+ A& S2 H - }) p- N+ b0 \0 B0 S1 j9 L
- }else{; B" U0 B" A* Q" v
- echo "请求失败";- w7 `! K ~" C; T8 K% w
- }
! `, Z5 L% |$ _: `( L - //**************************************************
0 C7 Q1 x) J3 _3 b2 s -
0 x2 F1 c+ m! _5 _- x - 8 ~) H* f; _# Z0 V- ^" Z, Q
-
/ h3 L, Z" D# T9 K7 X5 P" ` -
: ~# `# Y3 |! q# D j; E/ r; H5 W - //************4.图像识别************. e0 A8 z0 f7 `' G3 L3 ^5 x
- $url = "http://japi.juhe.cn/image_recognition/check";
3 q& h4 Y7 |( u. d - $params = array(( G5 [4 N; J' H( ^0 E! N. e
- "file" => "",//上传的图片4 b2 m+ \# ?7 F6 N$ q9 L
- "key" => $appkey,//APP Key
% S5 k) ~& Q$ z* A - "pname" => "",//包名9 w) ~/ ]( r3 K# P- b+ k8 w% ?. q
- "device_name" => "",//设备名称(如android OS或iphone OS)9 w% E, Q* s9 o
- "device_version" => "",//设备版本(如:4.0.3)2 h+ i( n8 @5 }) m) i$ k! H5 y
- "latitude" => "",//纬度
6 a0 s V9 h7 f7 T; _ - "longitude" => "",//经度
9 t, n, j3 T p2 K3 y3 z - "uuid" => "",//设备id
' x7 ~0 W+ N5 e$ g- P1 F' e - "zone" => "",//请求地区% e( b8 n" @9 X' W
- );' J6 j7 p+ H* P% a' t3 `
- $paramstring = http_build_query($params);9 w2 ?- Z" x% t y5 P+ j {
- $content = juhecurl($url,$paramstring,1);
! f- W# K& |( o* f6 Z3 R - $result = json_decode($content,true);
6 x' [4 u! x3 a$ r! T1 w) t: c - if($result){
8 r. B% T( d2 O: c - if($result['error_code']=='0'){
% `# C) J% F2 @) D' \ - print_r($result);4 b! u' V6 F4 m
- }else{
7 i7 T1 |) `% X - echo $result['error_code'].":".$result['reason'];. E9 e4 E0 F' _/ G# O
- }, E- ]. ?( D- W
- }else{
; D& w5 R8 x# g. ?$ ~8 g/ o1 X - echo "请求失败";
9 H. I' Z( e. a, ] - }- d/ T& q! D1 _* p# ~3 l0 ^6 k8 I
- //**************************************************
! e' j" h; w7 S - $ b8 p6 t6 s' A* |0 v9 @8 H5 i
-
: _% J: H6 E# P( p" | -
" Q' _7 @! h2 f) l" K. j9 M9 e1 a/ ^ - ' [7 y% x, W4 j( q' f
-
2 C% G( X3 I( C/ o/ W/ X! Z( N3 V# B - /**
/ d" c3 u$ A1 v) |0 K" z; ~ - * 请求接口返回内容' n4 P: f& r0 V# ?2 q! d& p
- * @param string $url [请求的URL地址]" e v- P* y& N4 \: N7 k1 q" z
- * @param string $params [请求的参数]
5 I& R; G7 ]/ i9 Y - * @param int $ipost [是否采用POST形式]8 p* ]! _+ ^$ \3 ~* C
- * @return string1 B2 V0 G$ x+ E9 m& P2 f5 e0 _8 g
- *// n" \4 F3 v9 z- h, t* j, r
- function juhecurl($url,$params=false,$ispost=0){- X+ p4 K3 W, Y& a
- $httpInfo = array();
% J: m* |; u3 ` o, u8 q - $ch = curl_init();
/ ~( ] i- O+ Y7 J -
j4 [" w8 |1 [( D2 w& W" D! K - curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
+ u2 ~0 v* @) x0 P8 @ - curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );5 \' e) Q1 p0 C# ]3 q
- curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );5 B0 O3 K1 z% M: Q3 @
- curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
: b2 u/ z# ]% \* N! ] - curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );- @8 R$ C7 W, G1 X* y
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);! ^4 n1 x: S) K6 e4 @7 ~
- if( $ispost )
; ^. s* T* U& F: U5 L - {/ U) X* Q, L6 k/ \, }2 x$ Z
- curl_setopt( $ch , CURLOPT_POST , true );: s, U5 ]2 ~! U* R
- curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );7 f4 u0 o8 _, x! J( E0 e# ?
- curl_setopt( $ch , CURLOPT_URL , $url );
' _: L* {6 g, G - }6 k* |5 f2 q B, @# i0 i
- else
) L' o9 s6 y! b/ l+ E/ v - {: K* D3 d9 S& U! \- B* Y7 _
- if($params){: y: x6 z2 t, j8 u5 B8 F2 i6 k
- curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
- e- F& t% C1 p+ ~0 j5 E - }else{$ y8 {5 w, E" O! e. Z
- curl_setopt( $ch , CURLOPT_URL , $url); t" _, e6 n: Y0 [# H
- }5 M O# ^, z1 _4 E6 ] `
- }
' b* s* U$ z V* c0 `" A - $response = curl_exec( $ch );& D* w, V. ^/ w- F" |% g
- if ($response === FALSE) {2 w# j' h1 m* u' d. z% g
- //echo "cURL Error: " . curl_error($ch);
; h6 k: c5 ?" j- `8 |; f+ ~! t - return false;1 Q, v' O4 S9 w) L' k0 X
- }
1 ~9 }6 u5 w% J5 j - $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
5 V; T. H4 O' V& ?# j9 s r - $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
w* t- g) \3 ? - curl_close( $ch );3 }5 r8 e w5 U! ^9 m
- return $response;
: W% ~+ t/ z d8 I D; P* w3 Z - }
复制代码
3 ^: U% q" q6 }! h- h2 U9 x* ]6 v; A) m* [$ H& Q7 v
|
|