管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。
) q( ^$ G& f0 N! l1 r6 E1.添加商品信息" D& z1 U% d4 e( I8 n
2.添加图片: T+ {! u: Q6 U4 D U6 p
3.查询所有产品
1 |+ ^% _! V, N& i8 o4 Q4.查询某个具体产品信息- E; H9 i. J0 l$ }4 n
5.删除某个产品
7 D6 j6 n5 p! x0 B8 {4 y6.删除图片( `" V: ]5 x+ e" \8 A
7.图像识别
( G1 D4 k/ c; x+ T' ~" |- @; h+ W9 u- C: z/ F" ?
图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey
! G( ?4 l( I7 f% P
5 K/ t& [' K5 {- Y3 JPHP示例:/ ^/ a% C2 m- l. j# [7 T" C0 O
- <!--?php3 Y7 n" u; F" ^6 a1 H" |2 U5 q: t% l
- // +----------------------------------------------------------------------
b" g: A0 `, C: }1 J - // | JuhePHP [ NO ZUO NO DIE ]) f6 ~! a8 b% Y. n
- // +----------------------------------------------------------------------7 y9 e! s! }& \. W
- // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.
0 b) B& l% d" w ? - // +----------------------------------------------------------------------
4 L1 `5 j$ [( Q3 z& |1 V1 w1 g3 ^ - // | Author: Juhedata <info@juhe.cn-->; W/ X7 s( a; e0 |1 ?& ~
- // +----------------------------------------------------------------------
/ r, O+ t/ j) ~& x. ? - # o$ x J( K" h% m0 y$ ?1 v
- //----------------------------------7 T& m8 X- t W: ]1 y8 u2 w
- // 图像识别调用示例代码 - 聚合数据
, ^" e% C* o m - // 在线接口文档:http://www.juhe.cn/docs/117% E- }' K) [% c7 _- j4 w: X7 X$ N% i. U
- //----------------------------------
* y' E+ p" v2 E0 Q3 V/ M% u: S* r - : f5 {' Z8 N- ~
- header('Content-type:text/html;charset=utf-8');
/ Z# P# r) |, }6 l. M6 e - 3 n8 v! Z. T. q( s- j3 G
- + p1 C! y7 ~7 A: D+ I9 P
- //配置您申请的appkey5 Q0 m# ^, k. M* N0 N
- $appkey = "*********************";
9 N( ?# O3 n( V- @# e- \ - % k1 B. N. J B( W7 C6 {
-
" S6 c) K% I9 u$ z6 I$ z# b: @ - S6 q Z- l, P/ U" |
-
& @' S- @0 i0 F- L - //************1.图像上传************
. x4 t1 Z" t7 P1 a$ ^3 I - $url = "http://japi.juhe.cn/image_recognition/upload";
9 Z6 ]+ Q9 y9 v- ^/ S$ T - $params = array(
) U! Y1 M3 _6 G t# r - "file" => "",//上传的单张图片
" Y0 O& l* | s a( T5 f5 w' S- F8 ?' O - "key" => $appkey,//APP Key! Q" Z0 ~7 F5 ]- `/ `
- "pname" => "",//包名
; e. G1 L8 s3 k - );
/ \- ]4 ^) a4 M - $paramstring = http_build_query($params);
# I, S, B1 {5 C, N$ d3 t8 J - $content = juhecurl($url,$paramstring,1);
8 l% s W1 s$ e* g$ s - $result = json_decode($content,true);: W2 G& X: W% X8 l$ c
- if($result){
% @7 E0 j0 N+ d3 H2 p% y5 e - if($result['error_code']=='0'){
# a, ~! H/ T G( j6 O( C. u/ q - print_r($result);+ Y/ S7 f% k/ Y6 e* h) X5 b
- }else{
o2 v/ m* n: T- ]: a0 G - echo $result['error_code'].":".$result['reason'];' N- {, ^3 ~5 E! u
- }3 d/ j a4 \+ \0 X
- }else{
: R5 K0 `5 q6 I% A; S$ Z - echo "请求失败";$ W8 v% e. i: F* `
- }; i8 q- X+ J8 {0 S0 L
- //**************************************************
4 [. {) a1 @$ j, w" ] -
% K0 z9 M" j9 d$ X -
+ Y, [' B7 D) |8 I- p+ U, a -
7 T) {0 V5 u* c0 L! s8 ^ -
- `+ Y7 ?$ a8 H) g - //************2.查寻上传图像信息************7 Y8 H/ s0 H" p9 U, K( S
- $url = "http://japi.juhe.cn/image_recognition/findAll";
# j# V) o6 t( k - $params = array(1 ]# Y- e9 a( Q6 q4 ~: c
- "key" => $appkey,//APP Key
0 j: `0 w" W8 g6 J, {: @ - );
0 n- c" |$ e& t; N2 ^; q! Q7 Z$ q - $paramstring = http_build_query($params);5 b m1 O ~8 P+ a) L/ [
- $content = juhecurl($url,$paramstring);( P9 |. F! }& F I
- $result = json_decode($content,true);: k/ q/ J, [, M7 o
- if($result){
+ m( @* ~! z- s - if($result['error_code']=='0'){( t' j& w% w* ~0 n
- print_r($result);. W" Y4 e! S; h* V
- }else{, H [% i- V/ W
- echo $result['error_code'].":".$result['reason'];( t; T) M9 l3 {8 n @, w5 L1 d
- }8 [0 y& b+ k, M! |" ~' \+ Y! {1 e5 g* ^
- }else{5 `: j- q4 A: U0 I- P6 f- Q4 D3 R
- echo "请求失败";
) A4 j1 b, c6 j( f6 ` - }
4 C2 \5 K) d; i - //**************************************************
; E/ O4 v+ K) }; B+ z -
2 m; c- A3 f* m& g4 j. J -
G$ P6 U' T' U& n- ?3 \ - % \" K% ?1 m$ B1 a* b
-
~0 v7 S& m* t! s4 w - //************3.删除图像信息************) p+ V# t$ U5 `* ]) X2 ^
- $url = "http://japi.juhe.cn/image_recognition/delete";/ T: |, S8 T8 o6 c }
- $params = array(
# I7 K& s8 B1 Z! x - "key" => $appkey,//APP Key
; y, b1 S6 F! R9 G1 ^4 Q - "imageId" => "",//图片ID8 }. N: `+ a4 }' Q6 ~, f! d2 }$ F& A
- );% `( ]; l7 I9 ~8 F1 ^
- $paramstring = http_build_query($params);
# S0 x* m! @5 \. ~7 B - $content = juhecurl($url,$paramstring);# M6 i# S I/ g' s- b# B0 Y$ v
- $result = json_decode($content,true);
5 m# R) j, ~; U' r' L - if($result){2 F' a# @; L# k
- if($result['error_code']=='0'){
. T# d+ w: V" l7 o - print_r($result);
2 y. p! C# C* R" e - }else{
3 A$ T E$ J. J, n; r {9 ~# D - echo $result['error_code'].":".$result['reason'];
- t' W3 C# M; P L+ i6 k - }
. Z% h( Z& ]; F! c5 e1 G7 d - }else{
1 G; }- C6 p. O8 q/ j6 r; ]) ~ - echo "请求失败";
" R: k0 O# u4 I C6 d0 L6 l5 f4 h - }
- |7 r0 R; [- s/ x - //**************************************************
- T u* H# R2 V. e. W% x. e - + J) ?& s D5 P# w
-
: x3 g1 l" f2 z) d5 G; C - * [5 i- Y# g G4 v( S
-
" I4 |" o! ]8 A0 l% [8 Q - //************4.图像识别************. _4 S5 Q7 R7 X& i3 n$ N
- $url = "http://japi.juhe.cn/image_recognition/check";% Y$ |: o( g# r8 p5 p
- $params = array(! c( K1 Y4 @4 D! u3 H
- "file" => "",//上传的图片6 y0 z/ O* L$ L% S; G7 F+ x" ]
- "key" => $appkey,//APP Key
# Z! f- X1 f# u, b - "pname" => "",//包名7 U2 a1 o6 D' c9 X$ M
- "device_name" => "",//设备名称(如android OS或iphone OS)
4 Q$ M; T- v( d8 g$ u+ F; n4 i - "device_version" => "",//设备版本(如:4.0.3)
- j# @' @$ x" K/ w3 G {1 A - "latitude" => "",//纬度
0 e+ P$ M, ~3 b3 m4 ^1 N4 g - "longitude" => "",//经度% l- L' H z! [6 ]6 E
- "uuid" => "",//设备id
, _+ U; U, @3 l8 j! n' h5 }0 R! L - "zone" => "",//请求地区
+ d! T( p! {+ n. V8 } - );
. a- M3 {0 c3 r/ [: e - $paramstring = http_build_query($params);
7 _% J, [( S4 p! M) F& ^# w, K0 e - $content = juhecurl($url,$paramstring,1);
! ?6 T% [ k9 w6 u' e5 t) l - $result = json_decode($content,true);$ A/ M% P' z/ e
- if($result){) R* p1 T; l/ V6 K5 e
- if($result['error_code']=='0'){
) D8 G/ f4 j8 o3 i( k% Y) N3 i - print_r($result);( X8 `# e: l0 }1 v: q( i2 V$ q
- }else{
k: v0 {1 h! o* w. r - echo $result['error_code'].":".$result['reason'];+ V9 M- _+ B7 x9 ]
- }. L! |3 g) \! L$ R, N0 O
- }else{
% W7 r9 B3 i* e6 k d) j - echo "请求失败";) q& B5 o$ G% y z8 }
- }
g% l, y; I4 L' E: ]! z+ O - //**************************************************
" H$ C' G, w7 ?) U: ~& Q+ z6 U: U# @ -
0 M+ p2 z7 u1 J+ g( m8 ] -
2 k0 Y& p6 h! j# y; r; X9 [, a' k -
# ]' N7 L' ~( H; p; ^ -
9 \$ T+ G+ c# [5 \ -
/ q1 W- y j! t - /**
8 ?8 ]/ z/ `7 N - * 请求接口返回内容! H$ I7 X) v' d5 ^2 j W7 m! C
- * @param string $url [请求的URL地址]
; n# e: w) H& k# A8 N e8 i - * @param string $params [请求的参数]3 y5 l4 I7 K& x4 Q* [
- * @param int $ipost [是否采用POST形式]# H/ u6 {1 R, U# T& {
- * @return string
+ k# `. Y1 K: M8 }' w0 ], O - */4 v2 W$ m: P+ L. j6 K% ]4 Y; ^
- function juhecurl($url,$params=false,$ispost=0){( r6 T4 T! a) Y( ^9 ?9 W
- $httpInfo = array();
9 [0 s" P2 ?: z6 o3 A - $ch = curl_init();2 y" B# y3 S' y+ s# b
-
) _: b' r7 p# O9 t: @ B - curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
* O& g8 ?" ]3 M - curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );% T1 f+ e& l4 s7 X
- curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
* d/ t* H3 Y- q* C - curl_setopt( $ch, CURLOPT_TIMEOUT , 60);: ?3 q: M. Q& e# h( H1 o
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
$ B7 K; s2 J/ h$ t0 s( G - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);/ g. H$ P! M2 k3 B6 ~
- if( $ispost )+ |% Y; Q. ]- m* k
- {1 w. ~$ x( n& K# c
- curl_setopt( $ch , CURLOPT_POST , true );6 H- J E' J5 f2 \, O
- curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
6 F4 f3 Q2 `& g7 j1 _7 l - curl_setopt( $ch , CURLOPT_URL , $url );2 f( w* a* X* C6 f7 {) h7 D
- }$ c2 [ l* H4 H( N, K* e! _! {
- else
5 y$ w/ Y' T( [/ R" E1 M - {3 e8 k# n p2 h
- if($params){- b1 b3 P' F% G% N$ G
- curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );1 I/ m9 i$ Q+ M) r
- }else{$ `3 n+ v5 w8 p
- curl_setopt( $ch , CURLOPT_URL , $url);
: C* l. [% O% n2 g5 J9 k - }- Y1 i/ a8 j. x+ c* `
- }; m9 y6 R3 g5 n. p- a8 @) g! i
- $response = curl_exec( $ch );
7 h2 {' D; q: r! N8 C - if ($response === FALSE) {
6 R+ Y6 f+ K" C6 } - //echo "cURL Error: " . curl_error($ch);
. Y) l& }) g+ q! Y. D; N - return false;
" e8 o. U% a' P3 ]5 ^) D - }8 n5 \' |; ?: H( u8 j) \$ _
- $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
) `& N. @/ P( h x/ o v% m3 O - $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
, D5 J9 _0 R: w& G: k$ b: a - curl_close( $ch );$ j' b# s2 a5 h! V
- return $response;0 B( K' ]$ i3 \) i+ u6 D @( u8 Z
- }
复制代码
# s: W* ?/ k* w6 s
6 T" B/ J: `7 P7 R' Y+ ] |
|