管理员
   
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。8 ~$ V1 m. P. ?( u0 t6 [( m
1.添加商品信息; `8 W2 m/ K' b+ ?% E5 ?+ l& x% i
2.添加图片
1 s E6 W! Y/ R9 m7 ~- O1 ]2 n( X+ [3.查询所有产品
1 O' e; j3 t# F+ u& f8 Q: v4.查询某个具体产品信息. K. C; s5 y5 R2 n& G5 \
5.删除某个产品
$ |8 x: j3 j% T9 s3 @1 |6.删除图片
6 p, A" V( q5 ?3 H5 b" {7.图像识别7 `" V1 z/ n# `( ]$ l8 Q
( y: A0 u: R/ t2 w: J& j图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey
1 ^; m S. M" \5 M# ^. r2 ]& c+ ~, z: }: U: f+ V
PHP示例:9 a. q0 V" x) T& H8 D* v
- <!--?php) M' ~+ q4 u% s3 m* G
- // +----------------------------------------------------------------------6 i3 j1 a5 ]! Z$ e, A$ [
- // | JuhePHP [ NO ZUO NO DIE ]
! y, y/ @6 C( s$ O - // +----------------------------------------------------------------------
: g/ y" I, Y5 m' k0 @. n2 A' r - // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.
4 F6 d+ a, g: [, Y3 n+ i - // +----------------------------------------------------------------------
& u; x4 D+ w M1 P - // | Author: Juhedata <info@juhe.cn-->
% s; o, n# X3 y( P Y) o* C; | - // +----------------------------------------------------------------------
/ h0 t6 b9 Q2 Q# ^' Z -
5 N: I8 O# M; } - //----------------------------------
" t$ F1 p, _! e% _& o. ~6 { - // 图像识别调用示例代码 - 聚合数据
4 B. M* o7 X9 z - // 在线接口文档:http://www.juhe.cn/docs/117$ }% _/ w4 h$ N$ F% W0 Z/ ~( U
- //----------------------------------
7 V: E# r& i1 [, ]. w& W0 C -
5 [; [& s( [* m; d4 b- R8 p+ e - header('Content-type:text/html;charset=utf-8');
5 m# Z" o5 F: W+ C. P - % B6 p; T* I2 X6 B
-
5 ?& _; v+ }4 p: [: U5 a - //配置您申请的appkey w1 z" E, A. s+ Q
- $appkey = "*********************";& ~6 G3 K& j$ G- F9 U5 q) {* N
-
; S: Z4 R$ N. y! v7 w7 j- a3 y -
6 N" C6 Z0 k! j- O! u! [1 o& | - * C) ?$ M4 d* }/ Q& t3 _
- 2 f3 r" Q7 w# Z, ^
- //************1.图像上传************
) ~% J9 e; r! | T - $url = "http://japi.juhe.cn/image_recognition/upload";
( S+ l* U. X3 f6 ]" l5 j - $params = array(
5 N$ |) i) W0 ~ - "file" => "",//上传的单张图片
7 D$ j# M, G9 w/ m8 B, y5 l) s - "key" => $appkey,//APP Key
7 T8 W0 W3 L2 O( ^: @. O$ [ - "pname" => "",//包名
5 E/ _, c1 ^9 n0 j - );
$ y9 n/ C/ w8 A" C - $paramstring = http_build_query($params);) z, O( Y! E! W, B" q# O' n# O: i7 C
- $content = juhecurl($url,$paramstring,1);
3 I k+ ?6 n4 g/ K. a d5 b8 R - $result = json_decode($content,true);
/ N. h/ z8 i3 q0 J3 N - if($result){/ m. A6 O: o I7 ]+ {( v. \) }
- if($result['error_code']=='0'){$ S9 }6 N9 Z$ A' h" b e
- print_r($result);6 R8 T f4 h& U. X
- }else{1 N4 q3 n5 M% g( r' D
- echo $result['error_code'].":".$result['reason'];
$ O) H: F9 a0 l7 c) u6 ~ y - }
# v# \# v( s6 J9 n# c/ e - }else{
$ Y! a7 J7 D, s# W$ O( U2 o& A' | - echo "请求失败";
6 ^( u5 Q% V/ h6 Y8 [! l: ^ - } J0 A# l ^/ j! P
- //**************************************************: k! B, h. t: w, O3 I; F
-
/ n0 {+ ^& ^' e7 T T( f -
: t, S, L# T }8 g$ T -
3 B$ _$ E9 o/ F, I - 3 s5 r& Y: S& s% J; }6 v
- //************2.查寻上传图像信息************
9 F$ C0 s8 w U/ x3 a - $url = "http://japi.juhe.cn/image_recognition/findAll";( U% r6 k: Y* a" A. q
- $params = array(
% L# f$ Q3 ^: R1 P. \, g7 J - "key" => $appkey,//APP Key
$ c7 [% F$ c; h! S- c - );
4 s2 E. p9 E# n/ l% [ S - $paramstring = http_build_query($params);4 h: U6 Z* |+ ?; }$ T, k+ s
- $content = juhecurl($url,$paramstring);$ {, c9 x& v( B! R, W
- $result = json_decode($content,true);
( j1 o. |* y& T8 o# `9 \' V" u - if($result){
% J# }4 t3 Q( O4 ` - if($result['error_code']=='0'){
' @ Z9 P6 r* N* f' L+ f - print_r($result);
* L3 W$ m: b7 B: A0 ~' N/ i' {; f - }else{; i9 k& ^" L( H( X+ C
- echo $result['error_code'].":".$result['reason'];
6 {1 g# C& i" [& Z - }. o0 @8 P- Y" r3 L5 J+ `, A
- }else{! \% n' s4 t: B
- echo "请求失败";
. l7 T: \2 `3 o1 u - }$ \: {' X9 }7 o, n
- //**************************************************
9 x* F! q: y# |( j, F, e - + k; i! F% [% g8 D3 d
- 4 Q( @. M* s4 w9 j6 F
- ' g& q( _$ b9 A
-
( j. n$ r" K* ~ - //************3.删除图像信息************
6 U- J5 ?. j/ E( k" w2 D - $url = "http://japi.juhe.cn/image_recognition/delete";3 V9 K8 l3 M8 g
- $params = array(0 t! r8 p4 I" P
- "key" => $appkey,//APP Key6 o7 [- k9 k) T! M# G/ B- y8 \" a
- "imageId" => "",//图片ID
4 n" E7 L8 I" u. U - );
9 E* ^6 |5 e3 K- N m - $paramstring = http_build_query($params);
! O8 b2 y3 I5 z - $content = juhecurl($url,$paramstring);- G) t9 `: N1 Z% Y* L
- $result = json_decode($content,true);2 u1 `- H) [$ X# V% g2 ~4 @+ n/ @
- if($result){' y2 ?9 k& o b2 O3 y: y: Z: o$ S
- if($result['error_code']=='0'){
+ c" a* ?; D& O2 Z - print_r($result);
3 C8 }* Q) A% T: y) N+ V+ r# B7 S - }else{
! v& O2 K6 [3 D- _9 Q - echo $result['error_code'].":".$result['reason'];
7 ]& L& ^3 C5 k2 M% f$ D" i) o- W - }
% x+ ? \! q! i5 G; z7 Q3 [9 j - }else{9 C9 ^# ]$ z9 v. |$ L+ O
- echo "请求失败";! Y$ F8 d! |3 P) Z; Z6 O. G d9 M
- }
& |) S, j I J1 P, U4 m - //**************************************************. _. `. Z3 s+ W% f
-
2 q. n$ f g4 q, r/ d$ z8 |. Q - $ G: u, g X$ O8 V' t
- # Z' T8 L$ ]8 a/ w
-
$ c5 r' p7 I) k: j2 d - //************4.图像识别************
0 R- {: h) |- J2 \4 V - $url = "http://japi.juhe.cn/image_recognition/check";$ s. W1 ?3 O- |
- $params = array(
9 r$ H G X6 u - "file" => "",//上传的图片; C3 ?1 `' \- R$ F, F
- "key" => $appkey,//APP Key2 g5 b e) {/ O: @4 m
- "pname" => "",//包名
E h& ~) p p6 l - "device_name" => "",//设备名称(如android OS或iphone OS)
; z# Y; T' k% C# H4 y; b" Z' x" } - "device_version" => "",//设备版本(如:4.0.3)2 s. n; b, N. O
- "latitude" => "",//纬度
; \5 b/ y5 z! E - "longitude" => "",//经度
: o; u/ T1 ?. d5 Q - "uuid" => "",//设备id
5 _& j" U/ y( K* ^1 n - "zone" => "",//请求地区 o) Q! y0 Z6 p# S
- );
7 x2 q& T( Z1 N: f# O5 `' @3 B - $paramstring = http_build_query($params);
) v, L' ~, o2 u$ |5 M& G - $content = juhecurl($url,$paramstring,1);0 L/ `7 ]2 B6 K5 R8 u
- $result = json_decode($content,true);
' h1 d" }! D) @2 @8 x+ `" i: P0 w - if($result){
/ h$ g7 k6 E' f" ^. |+ w - if($result['error_code']=='0'){
6 e2 g7 ^/ y: K2 ^# M' n; D3 t+ ^ - print_r($result);
+ r1 B- O9 S) {8 E8 A' s- G - }else{: x4 Y+ n; E) P0 D+ ^
- echo $result['error_code'].":".$result['reason'];
! }& @' _6 g9 e/ J8 i: x - }
b9 K+ A+ P9 @/ u+ W. H" n - }else{& f z! s& B. m; G2 E9 E
- echo "请求失败";" h8 y8 m$ k! a8 h
- }
. N- t& l S, N0 K" M L7 Q - //**************************************************
, N4 o. Z! d6 \4 t6 J# Q+ o8 W8 n l -
8 T7 \- }3 w T$ T6 Y0 ^5 N$ i -
. H" n% T/ X& j, F3 e+ h -
" H8 S2 z1 D o' S X8 m) k - , c: O+ C9 D+ w) m
- 3 ]' a7 s6 g: Z& a
- /**
; Q% a9 a$ Q0 h% l* \( v - * 请求接口返回内容
+ ~4 ]" r1 ]% ^8 k - * @param string $url [请求的URL地址]5 Z+ u# i7 {4 L- F( `# w6 Q9 r2 p
- * @param string $params [请求的参数]
( D/ i1 ?+ }4 M" z - * @param int $ipost [是否采用POST形式]
. l n7 B- t4 Z0 f! k ]3 r, _4 q - * @return string" Q+ y5 p+ s- _. P0 l# B/ {
- */
: W' R! E3 ` ` - function juhecurl($url,$params=false,$ispost=0){
' u1 }$ D+ z6 T0 l; Q. z - $httpInfo = array();6 Y% x! r! ]6 u: W
- $ch = curl_init();% h6 @, c# p- p* C4 n- J6 R6 u
- 9 \" z' N/ p! y6 Q
- curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
) u9 e F* _; y5 B1 O% w; T - curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );
0 L+ d a4 M; E5 | - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );4 Y% r6 X+ k, ^1 V3 W1 |
- curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
, R3 i2 W' t+ v - curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
* v8 |, u9 M' P% T - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
: [4 }- E1 ]; v! h - if( $ispost )
6 N) o4 K" `! {% Z# ~ - {- o/ W3 h$ P# s P! {
- curl_setopt( $ch , CURLOPT_POST , true );7 O* b4 K( \7 z+ e8 i
- curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
& K4 T, w7 {( O4 [; a" }: y3 t - curl_setopt( $ch , CURLOPT_URL , $url );0 @: M" u! Q. S+ h v' h' w9 t" B# l
- }
1 }0 t# b& a; h! U0 g - else& ^. ]) |( O+ q) v. T
- {( p, K. X V5 b: A% T
- if($params){
5 h; E! ]( p# F2 R$ t5 t" I - curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );& {, v3 x: p0 A6 [
- }else{* U$ k- K! K* e) ]# o
- curl_setopt( $ch , CURLOPT_URL , $url);9 r3 c4 J' B% T2 t
- }
0 A6 k7 g4 E/ a) @& f) _; B* S- O7 Q4 \ - }
! j3 D+ q0 A5 L% D - $response = curl_exec( $ch );- f7 W7 F4 W; ^1 R0 N
- if ($response === FALSE) {
( H$ a* V' q% e# |% ` - //echo "cURL Error: " . curl_error($ch);
% E5 A, S: x3 n& a9 | - return false;+ a( R0 n2 g# x2 P
- }; G# Z$ v) h* Q( F: W' D4 E: b
- $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );! X$ p' s+ F& t
- $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
, N9 c6 R4 w1 p' H5 K - curl_close( $ch );# {! ]6 h" [" I7 F$ g/ S8 W; P
- return $response;* U$ a) Q2 i/ g% I+ D. Q" d6 q
- }
复制代码 6 E0 b5 L2 O; Y& \; I! x0 `$ G
% u7 w( i! G2 C5 M/ l' ~2 m. y
|
|