管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。
- u& ^; j: Z% Q, ^' d2 k1.添加商品信息7 }2 f% ^ }* W4 a) ^
2.添加图片
$ f7 f0 j6 f2 F4 m9 Z/ a1 P3.查询所有产品/ @, O. z' `) l! ?- e" x- O) H3 K/ S
4.查询某个具体产品信息* H: @- t5 }: l* v/ l% u! U
5.删除某个产品! i+ y* P$ N8 j1 k9 t+ N
6.删除图片5 B+ i' T- ?- t T" }, x, R
7.图像识别1 j% l7 c3 L' a* Q1 g$ V3 J" d
$ m' V5 s7 d9 q/ B; ]: t' l
图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey: `( P, `4 W1 ?+ J6 s2 G
9 M- H1 I O. N$ c; p- w" @% r
PHP示例:
. h# {4 |' |$ {! n( G* M3 q- <!--?php8 d; H" W( k' B
- // +----------------------------------------------------------------------
8 \7 l9 `& y Z. \5 Z, o5 b - // | JuhePHP [ NO ZUO NO DIE ]: x, I$ ~9 p) C
- // +----------------------------------------------------------------------) m" s0 l+ i9 E8 G) ~7 a
- // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.
5 Y' M0 w/ w: Y - // +----------------------------------------------------------------------+ L8 S4 V. R5 P0 n6 u9 r
- // | Author: Juhedata <info@juhe.cn-->, q* _* ^0 d1 r, Q
- // +----------------------------------------------------------------------
% Z7 D& v- Q7 ?- S J -
( d) s3 ^2 X2 ~0 j1 z - //----------------------------------
; p# Y/ D6 W& C4 L1 ?3 @ - // 图像识别调用示例代码 - 聚合数据
' j* \4 l" z8 e% j# {" r - // 在线接口文档:http://www.juhe.cn/docs/117
) b7 p# D( E- R; Y9 P - //----------------------------------; O# F, f" s' }$ K- T; ^7 i
- - Q7 @% _4 A% a1 G
- header('Content-type:text/html;charset=utf-8');4 S8 t- D) g" A3 z" _: f. I
- 6 z9 E3 Q |. j+ }( G2 `- H' r/ ^
- 9 B0 w+ R1 p( R6 ~
- //配置您申请的appkey
9 R7 s' I+ z. J, k6 R - $appkey = "*********************";% A& S2 [. k# G- I4 U# U/ S0 j# H
-
0 E% ]- }" A" S - / ]' m+ c; e4 b8 o
- / @1 t2 N0 g/ B( L% V. d
- 2 |( U! c5 z0 L+ ]
- //************1.图像上传************ q0 Y/ W1 |( m7 Q# i! Y) P
- $url = "http://japi.juhe.cn/image_recognition/upload";
8 K& S; w. M! o. \9 g - $params = array(# {' \" |2 g/ T* M! p
- "file" => "",//上传的单张图片
9 T2 n$ V4 z k& N) Y - "key" => $appkey,//APP Key0 F$ }, d+ n7 w( l: a/ m" A, j+ B
- "pname" => "",//包名' e" n/ O; i& B9 n9 Z+ @
- );
6 w/ z8 I8 @7 [- @& | - $paramstring = http_build_query($params);& ?: ~" ^) k* m3 q9 A. ]
- $content = juhecurl($url,$paramstring,1);
) y9 N8 v8 u/ l& K% x `- ?' Y% v - $result = json_decode($content,true);6 }( r2 g$ `$ F6 D3 v+ m" M4 L
- if($result){
$ i; V' v; ?) H5 I& N/ @ - if($result['error_code']=='0'){
9 b0 D9 N# K9 @: f. u# u0 X - print_r($result);, f# d6 G, b, @8 \8 i, |
- }else{
: Z6 I2 S3 s3 {! L - echo $result['error_code'].":".$result['reason'];
. j0 i; {- P# L# `- B( @ - }" A, X) B- A& s. h. o' U0 i
- }else{
N0 V! H1 i0 w# c' Y7 w4 J" r6 F - echo "请求失败";
9 U1 w: }$ [2 h" L$ o - }
, O0 {# L; a, G& { - //**************************************************
1 J6 O: \ i' t0 S, s -
/ j' x+ [4 _, m -
, C7 Y# l/ w2 k/ l M+ f7 x - |6 o: G; @6 `* b
-
0 I5 D0 d! p: a2 J - //************2.查寻上传图像信息************3 X- I. D# f; p- Z# i# \1 G9 ^! V
- $url = "http://japi.juhe.cn/image_recognition/findAll";
" U' z+ O' I: Q+ X4 D) I - $params = array(6 ~% O6 R6 v& a
- "key" => $appkey,//APP Key' P: d! t( \, n& e- b: R
- );
4 l3 h# Z C! ~ - $paramstring = http_build_query($params);
" ?0 I, c- h* V. z( O - $content = juhecurl($url,$paramstring);9 v/ m5 I2 L) u: n: S
- $result = json_decode($content,true);
6 y. J" [) ? h - if($result){& I" ~: s' r' [! j# t
- if($result['error_code']=='0'){8 O% O' T5 ^/ W/ z" ]
- print_r($result);
2 i8 s7 Z2 w' Q. J& d; k( ?3 U - }else{
: y J. \2 `* h, @, |, F - echo $result['error_code'].":".$result['reason'];
, }5 h6 u4 g' l' E7 t - }
# e( @/ O/ f% E! p0 ] - }else{0 h* j4 x% g( h. b+ w2 K/ i7 h
- echo "请求失败";
* O1 R$ m. k3 A; B0 j - }
. h9 R5 p4 ?6 g0 Y4 K - //**************************************************1 P5 F" A4 p9 n
-
. ^, Z. c/ {/ }7 |/ r* Q -
2 B% F8 Z; y, U2 g) u* K( G - , f- Z( }8 `: A5 U! i
-
0 R' |* v& {- g0 u - //************3.删除图像信息************
# E9 B& G4 r+ a4 ], s& { - $url = "http://japi.juhe.cn/image_recognition/delete";* x4 V" c& v. X. @: _
- $params = array(
2 o0 h' T s+ l) d6 c7 Y - "key" => $appkey,//APP Key
, R% w; s) ~1 r; d9 a - "imageId" => "",//图片ID
6 `* l$ A: A- M7 S# d* [% U - );+ S/ N9 J9 o. g% \. r8 K% T
- $paramstring = http_build_query($params);
% m7 c2 W# }, j$ k. d, Q5 G - $content = juhecurl($url,$paramstring);
6 }8 Y1 X: K3 U2 X% ? - $result = json_decode($content,true);
4 W/ _% r3 }% T9 B. ]. B5 p - if($result){7 D8 Q1 t! k2 O2 c c# H' M
- if($result['error_code']=='0'){+ B& j( ~+ P8 M: g
- print_r($result);( A# \, B6 p% o9 @7 F8 [) _
- }else{ E% r- I, v1 D: S; u9 ]- t
- echo $result['error_code'].":".$result['reason'];9 u" Y' {9 D& B0 R
- }* i) u% a% ^" {# Q7 l9 a. \* i
- }else{
( q- M) o6 }% ?( ^% W - echo "请求失败";
6 [+ q0 d# u4 X3 n7 [8 i - }6 f) c: y9 A2 l
- //**************************************************
" S+ {/ [+ n. C* x* B$ D -
" Y2 m$ F+ R: z8 X4 I -
% }8 \. Q. n# `) p6 h/ C - 5 Q" f& @) n& ~" c' V; L6 r
- 6 K$ z4 A* D: @+ V* }
- //************4.图像识别************
4 H ]1 I6 C ?. Y - $url = "http://japi.juhe.cn/image_recognition/check";/ R1 N! B7 u o5 p9 Z4 {% s* k* Q
- $params = array(
; t7 | H# q1 r, N0 I3 }" ] - "file" => "",//上传的图片
8 u$ [ a9 K. V - "key" => $appkey,//APP Key: s4 S! {. c9 }* i- N0 B
- "pname" => "",//包名1 t9 f/ b6 p3 ~2 u8 ]6 w
- "device_name" => "",//设备名称(如android OS或iphone OS)2 g) k7 l5 Q5 c- D9 M
- "device_version" => "",//设备版本(如:4.0.3)7 p- s# R) l8 d
- "latitude" => "",//纬度$ k: T2 h7 }9 E5 ^' a
- "longitude" => "",//经度
. E0 F+ ]; t4 j `4 A. i - "uuid" => "",//设备id
- A; @# V! m5 J) x ^ - "zone" => "",//请求地区
. H. g9 {7 E8 v4 Z% q! f - );! E. p7 u" m% h& t. p- h
- $paramstring = http_build_query($params);% K" o' ^. J4 F5 M
- $content = juhecurl($url,$paramstring,1);+ W0 n5 v' H$ e7 |( R+ U& K( i' y
- $result = json_decode($content,true);1 H9 f" b1 R: J+ \: P; n6 J/ `
- if($result){
5 Q4 g5 W1 ?' c r" v# r - if($result['error_code']=='0'){
2 U* R" F6 G4 W$ @) d; w - print_r($result);3 A; i1 s. z3 A: A1 y j) B
- }else{
3 y/ w" p0 Z# V) {7 J! }) B! _ - echo $result['error_code'].":".$result['reason'];$ v7 |3 t) y# c `6 [; c$ [9 o
- }7 i ]7 w- h6 O- Z
- }else{& b$ m5 Q8 z6 ]1 u
- echo "请求失败";9 m4 E* |7 @( D M" }7 _1 i, M' N, ^- [1 _
- }
+ T7 j6 q0 ^& V- v$ v9 Z2 n - //**************************************************
( w( _# m( {! t2 g; D0 K0 I - ; N9 x3 G' y/ p8 q8 {* }
-
8 ?7 g& B* a: F! j. T% U -
- J! [/ r1 r: s+ ] -
% a& }( O4 C# B% \, ?; Z" @ -
6 p/ O* A |2 Y/ f8 J4 ^- Y - /**
$ f7 L" e% ~6 K7 n - * 请求接口返回内容' Y8 F$ J% Z9 ?
- * @param string $url [请求的URL地址]
& H2 r( ~# r; ~/ J: t - * @param string $params [请求的参数]% D T2 J& g/ f- O2 k0 e9 ]3 d5 s0 {
- * @param int $ipost [是否采用POST形式]3 o8 f2 M4 l+ Q' B0 `6 C
- * @return string
2 \3 N, m+ B5 w) p - */
8 _1 U/ R7 ?/ w( S f8 w" Y/ \; J7 f - function juhecurl($url,$params=false,$ispost=0){
, p3 H! U: \$ z6 `5 {1 T* M0 H$ | - $httpInfo = array();
; v w. c- H6 ?# J6 A" {5 Z3 { - $ch = curl_init();3 S3 x% y5 h: m! q
- . @8 o/ [2 ?3 F+ H" i0 r# z/ w: @
- curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
- y/ C ~8 } I - curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );1 T6 I% p g% M9 F" P. }
- curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
2 y8 [1 |% @1 s1 r& b9 | - curl_setopt( $ch, CURLOPT_TIMEOUT , 60);* {0 g; X% R; k, `0 _) B* k" Y- }
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
' N, K' A! d5 R+ a - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);) I# t6 A. d; B7 i, c
- if( $ispost )9 x% l ~; l) B# w1 F7 b
- {8 m$ v6 L+ P( m+ B2 Z# Y6 o) a
- curl_setopt( $ch , CURLOPT_POST , true );4 d1 {- U: g1 ~9 o: A) N8 O
- curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );/ Z9 z y y8 y$ T5 d3 c, x+ J* |
- curl_setopt( $ch , CURLOPT_URL , $url );
; U2 k" d8 ~5 ]) } - }
) a; X* K8 j5 K/ ~# E; r - else
/ v3 R( k' F0 ~4 s( M5 I5 Z - { l0 _- N- k* F4 p# Q9 A+ Y
- if($params){# _6 o1 O/ R- f
- curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params ); Y# e6 F+ ~% n) ~
- }else{
4 L+ I* U) g/ l - curl_setopt( $ch , CURLOPT_URL , $url);
+ z! ~% D7 ^; V$ u9 j - }
7 X$ t" a( ]# B: X! W - }
# n2 {3 F5 H5 v - $response = curl_exec( $ch );
3 C, C7 @* R4 p5 L4 C, i8 p# S8 ] - if ($response === FALSE) {; Q( g6 z+ Q: a' F+ j$ f
- //echo "cURL Error: " . curl_error($ch);5 O- K- u* t4 I( }8 C/ D l4 X; D
- return false;
_: b6 `0 d9 @2 b( |; E- ] - }( V1 w J* g6 d: \0 z& C! B4 T' W; U
- $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
) b0 F; d- _; R7 D# A - $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
- T# z; p4 n+ A' }; E4 X - curl_close( $ch );# t: D" e: c& c
- return $response;" H0 _0 q3 V) ^% @* W
- }
复制代码
2 Q1 }! i, T' x$ i, T" D
; \4 t6 ?5 ^7 {; B0 d) ]% b1 X |
|