管理员
   
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。
# B! v" C8 c% r" u1.添加商品信息' Y/ M) y/ U; M6 J
2.添加图片
% l, A0 K( ?& }& o4 T" G P" S3.查询所有产品6 c% N5 E% O7 t2 y1 N& i$ m; ?5 G. T
4.查询某个具体产品信息
* U6 D! ]: A U/ a0 Y+ e0 {5.删除某个产品
& d* d2 d3 f' I- v/ ^% M+ M* w6.删除图片; d! A. c! r( e: J- j9 ?
7.图像识别* H6 I8 }5 E5 ?& m4 z8 x
5 Z% C0 R! z1 t+ Y. c
图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey9 e; s$ H" K5 J
& r# z+ H+ x; ]# E8 O3 qPHP示例:
' N. b* m8 x" k- <!--?php
% ^& Q7 }# {9 N/ j4 \5 j8 \ - // +----------------------------------------------------------------------
* m! P1 m6 z& z h; { - // | JuhePHP [ NO ZUO NO DIE ]
; E8 c" j, K) b: Z1 S1 U& [ - // +----------------------------------------------------------------------
% t- |8 e$ G( K5 x2 Y' G - // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.9 A4 c( [5 E1 g2 ^
- // +----------------------------------------------------------------------% V% |8 u b0 a/ u# W& V5 @: x5 I) I
- // | Author: Juhedata <info@juhe.cn-->
1 ^6 z# _5 ^, Z - // +----------------------------------------------------------------------! [2 s, d6 P2 U
- ! E* P4 K7 U) p: r6 @
- //----------------------------------% A( b. X m" w& C; l: l6 j7 i& \
- // 图像识别调用示例代码 - 聚合数据# d, u- }/ }. I1 n( d; b+ U* r1 v
- // 在线接口文档:http://www.juhe.cn/docs/117
+ x- ~0 H* X! j: y2 s - //----------------------------------
; F5 P: V$ ~; J w - 2 H! T, P; k2 s1 o8 P, m
- header('Content-type:text/html;charset=utf-8');, ~5 V: T/ \" ^- K+ i4 _! ]! V
- 6 u- @6 K! p: S6 K2 I% g
- . z- q/ k0 \% B/ X( P! }
- //配置您申请的appkey" {$ U6 ~2 x7 F
- $appkey = "*********************";
) x# ] P8 p7 Q1 M - 9 N; e3 S* [! ~; p0 c* B& E
-
8 G8 p) x- ]* y4 l" h( o -
$ a7 ^2 M& ~6 C' y. d$ D( D3 X) t1 F -
+ V& z0 R6 P6 Z' T - //************1.图像上传************5 E8 K7 O0 c+ U) j
- $url = "http://japi.juhe.cn/image_recognition/upload";
" t" i5 I" g9 d/ ^- @5 T - $params = array(
* ^) W& [( ? X: m6 C- t$ f. ]& n - "file" => "",//上传的单张图片
. d' I9 C3 v3 P8 @ - "key" => $appkey,//APP Key0 P+ n8 Y/ q* m% O7 {+ k* z
- "pname" => "",//包名
{6 a. h3 O7 M# V: l! V! T: h - );& c& K9 o4 P& l" Y2 J( O
- $paramstring = http_build_query($params);
+ L1 T. I# p# k* m - $content = juhecurl($url,$paramstring,1);
. F0 d( K( D' o/ j) I. j - $result = json_decode($content,true);4 ~/ W3 a0 [6 O9 v( ^; K/ B
- if($result){& v- o2 K( R. @
- if($result['error_code']=='0'){
: z) {& y& M2 [# N; g - print_r($result);/ p: C" d7 h4 h9 ^* e% J
- }else{
- J; Z) f! D( A9 r# |5 a - echo $result['error_code'].":".$result['reason'];* q% V3 [& u2 {5 Q
- }
$ P7 [+ R& L6 @/ T - }else{
- R; E7 w- N- G, J3 a' p - echo "请求失败";
7 A \* S; S$ K - }
$ I" F: t1 a) L. C - //**************************************************8 `: Q. x' S$ g7 ~5 k4 T
-
% C! w9 ^# T% ]! v0 g0 T - D; n9 T4 w* ?: U( }8 n
-
! ]' k, c( [; e! q5 I - 4 a2 n$ e& f* M0 m* f# B1 K3 W
- //************2.查寻上传图像信息************& k, S) }0 [9 E- R1 u7 i" v0 w
- $url = "http://japi.juhe.cn/image_recognition/findAll";
0 c. x! T. S) h( O% n8 R - $params = array(
0 N+ p- C5 `: x |( I - "key" => $appkey,//APP Key
. @3 ]/ m# B% d/ y - );! {: W! h8 t3 h7 G+ j9 Z
- $paramstring = http_build_query($params);$ b P7 L" u+ W: X
- $content = juhecurl($url,$paramstring);( G1 j% }0 P4 ~& T, T$ X! j
- $result = json_decode($content,true);+ G4 L: @5 n& y
- if($result){4 w: A8 Z/ s' {5 V/ m
- if($result['error_code']=='0'){9 {( H1 M7 v3 v! ?* z( Z
- print_r($result);' E) S' k5 P9 D: C, c6 e
- }else{! a j# z+ K3 c) X! N
- echo $result['error_code'].":".$result['reason'];- d" X! V. t, g# L
- }) B1 {4 r1 k9 U8 T4 T- l/ y6 e7 c( c6 M
- }else{
' c- Z, Z# `8 R8 z - echo "请求失败";
0 k+ h4 R v# j2 P# r3 ]) b! d8 E' f - }2 E) v4 V7 k0 s- n6 w- s
- //**************************************************9 I( i0 Y" n2 W, P' S9 z$ x
- 1 ?8 Z, x! N! [
-
7 e7 Y) N3 ?& p" e6 {) t - 7 w) z8 u& s5 d) e) y
-
+ B" h& D, u8 v6 e4 P - //************3.删除图像信息************
. W& ~/ L: ~! @! w. c - $url = "http://japi.juhe.cn/image_recognition/delete";
/ S" Z: L; C+ ^8 P - $params = array(! [# f7 ~/ P4 _
- "key" => $appkey,//APP Key$ S. W4 {5 f# I ?$ T
- "imageId" => "",//图片ID# u. v/ x% t# t
- );
4 n$ q! D4 |" p/ L - $paramstring = http_build_query($params);
5 p2 w$ ?, U- C' T# E - $content = juhecurl($url,$paramstring);4 T! U% q [& x. X$ w. P
- $result = json_decode($content,true);# [' U0 j+ I9 L- X# {9 y% L+ X
- if($result){) m2 n" i% o2 l( N5 E
- if($result['error_code']=='0'){+ U0 r; Q4 r- o9 M( N# d
- print_r($result);
) a( [" y" X% ]2 E- g - }else{: U# D" `+ C' o
- echo $result['error_code'].":".$result['reason'];* H- Y' E& x f0 d' \( W0 b3 {
- }
+ C! Z2 Y# g" p - }else{
! U$ _( {: k6 F) ` - echo "请求失败";4 l/ j) q+ w" M$ X! A/ ~: w: T
- }# _2 F4 R) l; N# H( E
- //**************************************************
0 ~) D0 U. V- f# d& X* z% z1 t -
9 j1 v! b+ B+ X, v - . k" T% y% V# Y" Y& n
-
+ Q0 |- K: f% l e -
! Y! s" d2 g; Z3 u* Z - //************4.图像识别************
$ S; {* B: G3 ]) ? - $url = "http://japi.juhe.cn/image_recognition/check";3 r" B! U. y: I3 I
- $params = array(3 C3 H0 {/ _2 `% M) Y
- "file" => "",//上传的图片+ b+ G6 J1 ~8 F
- "key" => $appkey,//APP Key5 B( Z# ]4 z- E/ H6 u4 J; ` V
- "pname" => "",//包名5 Q! R; C+ O9 }, x X; p
- "device_name" => "",//设备名称(如android OS或iphone OS)
8 N6 Z6 l8 X4 x# J' q7 {) x7 P - "device_version" => "",//设备版本(如:4.0.3); g' N/ k; l$ F0 L& C8 S
- "latitude" => "",//纬度
3 g2 J6 K2 u4 x' O2 M5 [ - "longitude" => "",//经度
2 C, n( f6 D- `3 h - "uuid" => "",//设备id! W/ ^* O3 S; P# q# t$ @7 k
- "zone" => "",//请求地区# ` A: \* G$ d- V) r" M6 `/ E
- );
% ^: k6 b) P1 h! c: e, z - $paramstring = http_build_query($params);) t, G# u% y6 \0 k
- $content = juhecurl($url,$paramstring,1);+ q# g" [4 C) E$ ?9 d, u7 [& \. q `
- $result = json_decode($content,true);
) H2 s: u( k, c5 B - if($result){- e4 b- T4 Z1 K9 `. \3 Q7 Z2 O
- if($result['error_code']=='0'){( d, F5 x; P2 }3 ?9 k
- print_r($result);
- e$ W( t+ v/ f6 W- V9 V5 I+ \ X5 u - }else{
7 L: Y, Y9 X( M) {: {! K - echo $result['error_code'].":".$result['reason'];5 N7 i# z$ I* R$ P
- }5 f2 i& G* n9 `, m) _1 [. c! T
- }else{; E. O# ~1 L8 S Q4 z# [. R
- echo "请求失败";! L; ~$ A/ i" ~4 q: W/ {: `- J
- }- o! ~1 o; Q, \: J
- //**************************************************
v: ?% w( Y B: x, I0 X -
; E* a, ^0 F: x( f -
+ t0 D2 G( l: n5 D; J* a, x -
1 T1 M! x+ z1 {0 a1 s: T -
" L0 p" _" Y. W6 F$ p2 v/ K# n - , Q' A9 ~( g: ^6 i6 @% t' y
- /**
3 p. B1 W7 @* S' t - * 请求接口返回内容
8 N7 F2 f- m+ n1 m8 f - * @param string $url [请求的URL地址]8 A4 [- _- V3 T) s7 R
- * @param string $params [请求的参数]
* M% O. F1 o9 l4 u9 } - * @param int $ipost [是否采用POST形式]
6 y3 W6 t t \* m6 c - * @return string' @2 s6 X; _0 u" \* H
- */
& m4 E6 G& x/ \* D5 K - function juhecurl($url,$params=false,$ispost=0){
# `+ G1 o, l$ O/ d1 v5 U - $httpInfo = array();8 K* V0 _+ e# j2 i
- $ch = curl_init();4 n$ g: N/ Z% I" S* y# }( C
- 9 P6 J5 H% O# Z. @; i" n
- curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
$ n1 F2 P2 h* _% r9 c5 c - curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );& K0 Q0 B5 g0 N
- curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
' t( D" [8 B8 j" H: ~) q1 X - curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
# i9 |, g! q) v# l; Z+ \" |& Z/ F - curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
4 O# T6 A: H% X* I& A - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); D1 `# W% L! N0 ]" a
- if( $ispost ); c3 B- Y9 Q3 G" R, G5 f# D
- {
L$ u" t7 H s - curl_setopt( $ch , CURLOPT_POST , true );7 t$ G# o5 e& r/ x$ }" r' U7 V
- curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );6 n; Y6 L$ N) Z+ x5 ^* a
- curl_setopt( $ch , CURLOPT_URL , $url );8 Z( e' a: l+ |
- }
' S, ~- H/ V- Z$ k1 V - else
/ V/ x9 { P6 }6 { - {
' j% K- }3 D' e - if($params){
6 v- A% ^7 n& z7 A2 |/ [ - curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );- L0 F2 ~% y3 `" c2 E8 p
- }else{" u$ @3 e2 b# g
- curl_setopt( $ch , CURLOPT_URL , $url);. U# w! F E, v! x
- }
2 i3 \+ s0 C5 _9 \ - }
9 }% j" B7 _% c0 o8 p - $response = curl_exec( $ch );
8 H4 E8 y. ?* E8 c e - if ($response === FALSE) {8 L) s! Y7 v" i# Y' q2 ~ ]: Z
- //echo "cURL Error: " . curl_error($ch);
- S7 _* O$ k' p& z( T - return false;5 T6 M) S- y/ m
- }: @3 X% z/ r0 P: Y% v- y5 C5 O
- $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
) z( e! A/ v7 v y& s - $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
: U. N2 v/ L5 i1 g( O - curl_close( $ch );
' ^2 T8 [5 T, u! l) x - return $response;
9 V4 A4 {# e( B5 q# b9 B - }
复制代码
, k1 f7 o7 W$ k0 k" [( L" R# C) D; I5 n) U
|
|